error handling prisma's post-deploy hook

2020-04-19

 | 

~2 min read

 | 

324 words

I was running through a few different tutorials of Prisma recently when I ran into an error when trying to use a post-deploy hook.

After initializing my project (prisma init) and following the prompts on the CLI, I got to work with configuring my .yml file that was generated to be slightly more robust.

Namely, I wanted to use the post-deploy hook:

prisma.yml
endpoint: ${env:PRISMA_ENDPOINT}
datamodel: datamodel.prisma
secret: ${env:PRISMA_SECRET}
hooks:
    post-deploy:
        - graphql get-schema -p prisma

When I ran prisma deploy, however, I got an error:

$ prisma deploy
Deploying service `my-service` to stage `dev` to server `prisma-us1` 493ms
Service is already up to date.

post-deploy:
spawnSync graphql ENOENTRunning graphql get-schema -p prisma ✖

The issue, it seems is that prisma couldn’t find graphql and so it failed to launch the process.

Looking at my dependencies, however, raised some questions:

package.json
{
    "scripts": {
        "start": "nodemon -e js,graphql -x node src/index.js"
    },
    "dependencies": {
        "//": "...",
        "graphql": "^0.13.2",
        "graphql-cli": "^2.16.7",        "prisma": "1.17.1",        "prisma-binding": "2.1.6"
    }
}

There are two fixes to this problem:

  1. Install graphql-cli globally (yarn add graphql-cli --global), or
  2. Add a script to be sure to use the locally executable prisma package which would be able to reference the graphql-cli also installed locally.

The former is described by Ashik Nesin on his blog. Doing my best to refrain from installing packages globally, I pursued the latter and added a deploy script to the package.json:

package.json
{
  "scripts": {
    "start": "nodemon -e js,graphql -x node src/index.js",
    "deploy": "prisma deploy"  },
  "dependencies": {
	  ...
    "graphql": "^0.13.2",
    "graphql-cli": "^2.16.7",
    "prisma": "1.17.1",
    "prisma-binding": "2.1.6",
  },
}

And just like that, my errors evaporated!

$ yarn deploy
yarn run v1.22.4
$ prisma deploy
Deploying service `my-service` to stage `dev` to server `prisma-us1` 197ms
Service is already up to date.

post-deploy:
project prisma - No changes

Running graphql get-schema -p prisma ✔✨  Done in 10.51s.

Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!