Difference between using generate and post deploy hook while generating the Prisma Graphql Schema?

Viewed 275

I'm new to Prisma and I love using it.

Apparently, I've been working on creating demo servers using MySQL for development purpose. However, when I try to update the prisma.yml file to generate the Prisma graphql schema file, I find there are a couple ways to do this.

First, using the generate property in the yml file like this:

generate:
    - generator: graphql-schema
      output: ./src/generated/prisma.graphql

Second using the post deploy hook method:

hooks:
    post-deploy:
        - graphql get-schema -p prisma

Hence, I was thinking which one of these is a more goto approach and what are different use cases for these two different methods?

Outcomes

The one thing I noticed when using the generate method: our generated prisma.grapql file is very condensed and doesn't have any comments written within it.

Snippet:

type Query {
  todo(where: TodoWhereUniqueInput!): Todo
  todoes(where: TodoWhereInput, orderBy: TodoOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Todo]!
  todoesConnection(where: TodoWhereInput, orderBy: TodoOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): TodoConnection!
  node(id: ID!): Node
}

But while using the post deploy method: the prisma.graphql file comes with various descriptive comments.

Snippet:

type Query {
  todoes(where: TodoWhereInput, orderBy: TodoOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Todo]!
  todo(where: TodoWhereUniqueInput!): Todo
  todoesConnection(where: TodoWhereInput, orderBy: TodoOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): TodoConnection!

  """Fetches an object given its ID"""
  node(
    """The ID of an object"""
    id: ID!
  ): Node
}

However, I want to know if there's anything more than this and as a beginner I'd suggest you to throw some light on whichever's a good approach to get the Prisma graphql schema.

1 Answers

I think the recommended approach here will be the post-deploy as it gives a cleaner output. The generate is mostly used for generating the Prisma Client that has the types and gives you all the required methods to access your data.

I personally have used generate as follows:

generate:
  - generator: javascript-client
    output: ./generated/prisma-client/

This will generate the Prisma typings that help querying for data in the models that you have created.

Also as you are getting started with Prisma, I would suggest Prisma 2 as that is stable and is actively being worked on.

Related