Recently the release of NestJS 7 was announced with amazing updates to the whole framework including the @nestjs/graphql ❤️ package.
We create a G...
For further actions, you may consider blocking this person and/or reporting abuse
Hey Marc,
Great post, thank you. There's a question many people ask, although it's not that easy to find answers for:
How can we (if we can) document the GraphQL schema (fields, queries, mutations) using code first approach?
I use code first, but I also want "DOCS" be more meaningful in the playground. If you know it and you can demo it in your examples, that'd be insanely awesome.
Cheers,
Alex
Hi Alex,
you can add a
description
option to the code first decorators@Query
,@Mutation
,@ObjectType
,@Field
and more.Here is an example how to add a description:
This documentation is added to the generated graphql schema as comment
"""DESCRIPTION"""
to the field or query, this is getting picked up by the graphql playground.Let me know if this helps you.
Hey Marc,
Thank you for the info.
The recipe seems to work, just tried it in NestJS 7. Apollo's GraphQL Playground doesn't make descriptions quite visible though. But they are there (the "DOCS" tab).
The set of supported markups is yet to be discovered. Markdown's
code
seems to work, don't know about the rest.Cheers!
Good idea to add markdown to the docs that helps too.
I am glad I could help :)
Nice, thanks for you post.
Thank you!
I am facing a weird problem. I am using
@nestjs/graphql/plugin
. Sometimes It generates the schema properly and sometimes it doesn't. Is there any issue with this plugin?Hi Humayun, can you provide a repo for me to reproduce? Maybe two eyes more can find the problem. I have not found any issues with the plugin until now.
and the main question. can I use schema.gql file auto generated when I use code first approach as schema.prisma???
I am not sure if I understand your question.
You use Graphql code first approach to generate your graphql api which generates the
schema.gql
.The
schema.prisma
describes your database and is separate to the graphql endpoint. You have to write your prisma schema your self.That means you can use both at the same time. Code first to generate
schema.gql
and write the databaseschema.prisma
manually.Does that answer your question?
thanks for answer. I get it yesterday, when start do it, not read) But this good idea, I think: we have slightly different between our schema.gql and schema.prisma. Cause we would be generate prisma use our ObjectType objects. it would be pretty nice.
Hi Marc,
Great post. I saw your repository and found out that you use Prisma Client there. But in official docs of nest they tell about Prisma bindings. What's the different?
Hi Mark, nice name by the way 😄!
Yes the nest docs describe how to integrate with prisma bindings which are used for Prisma 1. I am using the Prisma client from Prisma 2.
Here you can read a bit more about Prisma history prisma.io/blog/prisma-and-graphql-... which explains the terms.