7

Just started using Prisma as a way to integrate GraphQL and MySQL into a new project I am working on. It's great, I love how simply it lays things out. I have a few questions which are bothering me though regarding the workflow to follow when developing with Prisma.

For example:

Yesterday I setup the basic Prisma and GraphQL server as per the tutorial. It all worked well. I only have a single type modelled in my datamodel.graphql.

This morning I wake up and start work on another type and add that to my datamodel.graphql. Docker is running, I update the index.js with resolvers to support the new Model and it's Querys/Mutations. However, when it comes to running the system using node ./index.js I get an error saying it isn't aware of the new Model. I suspect the Prisma schema hasn't been refreshed/updated so i run graphql get-schema --project prisma but it tells me that nothing has changed.

Obviously I'm missing something. I am not working with Prisma in a way it would like. Can anyone illuminate me as to the order of events which have to take place for things to run smoothly?

The tutorial is great for getting you up and running but I feel like it doesn't well introduce developers into the flow of using Prisma on a day-to-day continuous development cycle.

Any info/insight/links would be very useful.

Many thanks,

A

UPDATE

For anyone else who has become a little lost about the workflow. Take a look at the CLI reference. It's very useful for all Prisma related tasks (not necessarily all things to do with your GraphQL server). LINK

TL;DR:

You need to redeploy your prisma service each time the datamodel changes so that the generated prisma.graphql can be updated with new functionality to work with the DB. I ran prisma deploy and voila!

A.Smith
  • 427
  • 5
  • 14

3 Answers3

8

You are missing the prisma deploy step.

You're confusing the data model (typically called datamodel.graphql) with the Prisma database schema (typically called prisma.graphql).

The data model is used by Prisma to automatically generate the Prisma database schema:

enter image description here

Please follow this gist to see the difference between the two in more detail: https://gist.github.com/nikolasburk/eef24cd0d907b4a3e073723054cf847d

divyenduz
  • 2,037
  • 19
  • 38
  • 1
    To make it more accurate, `prisma deploy` is to apply your changes and migrate the underlying database schema. But you also have to do `prisma generate` to update the auto-generated Prisma client so that it can expose CRUD methods for any newly added model. – tnkh May 08 '19 at 07:16
0

Don't forget to deploy your datamodel with prisma deploy.

You have a full working example here: https://github.com/alan345/naperg

Alan
  • 9,167
  • 4
  • 52
  • 70
0

In addition to the prisma deploy command which is issued in the CLI, don't forget to also issue the prisma generate command, Prisma generate is the extra step which creates javascript functions for all of your auto-generated CRUD operations from your database.

It might be that you don't want this extra level of indirection (or abstraction) although Prisma do recommend it for a number of reasons (Prisma Architecture)

There is also a post deployment hook you can enter in the prisma.yml file which then automatically runs your prisma generate command everytime you run prisma deploy. Leaving you with one less step to remember.

      // prisma.yml file

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

hooks:
  post-deploy:
    - prisma generate

I haven't talked about the use of the prisma client functions and how they are accessed through context but the very helpful and up to date tutorial is very well worth doing: How To GraphQL

Faktor 10
  • 1,868
  • 2
  • 21
  • 29