prisma-labs / graphql-prisma-typescript

🏡 GraphQL server reference implementation (Airbnb clone) in Typescript using Prisma & graphql-yoga
MIT License
748 stars 108 forks source link

There is some bug preventing from generating bindings for app itself #65

Open pie6k opened 6 years ago

pie6k commented 6 years ago

Steps to reproduce

Modify .graphqlconfig.yml to:

projects:
  app:
    schemaPath: "src/schema.graphql"
    includes: ["queries/{booking,queries}.graphql"]
    extensions:
      prepare-bundle: src/generated/app.graphql
      endpoints:
        default: "http://localhost:5000"
        prepare-bundle: src/generated/app.graphql
      prepare-binding:
        output: src/generated/app.ts
        generator: graphcool-ts
  database:
    schemaPath: "src/generated/database.graphql"
    includes: ["database/seed.graphql"]
    extensions:
      graphcool: graphcool.yml
      prepare-binding:
        output: src/generated/graphcool.ts
        generator: graphcool-ts

Run yarn prepare

Expected: complie bindings for app schema

Actual: Error: TypeError: Cannot read property 'type' of undefined when I've found out happens in node_modules/graphql-static-binding/dist/generators/graphcool-ts.js:48:89:

var whereType = field.args.find(function (a) { return a.name === 'where'; }).type.name; 
// field.args is undefined!!!

I was trying to dig a bit deeper but I then I had too little knowledge about project itself to realize what is really going on.

My workaround was changing generator from graphcool-ts to binding-ts and it worked but I have no idea why.

Also, it took me a while to realize I needed to add prepare-bundle: src/generated/app.graphql to app.extensions to have all imports working. My intuition was to add bundle: true to prepare-binding options but it was not working.

kbrandwijk commented 6 years ago

I think the culprit is the extra prepare-bundle on the endpoint. The config options are explained here: https://github.com/supergraphql/graphql-cli-prepare#graphql-config-extensions. Also, the app schema is not a Graphcool schema. There is some stuff in the graphcool-ts generator that is Graphcool specific, so your decision to use binding-ts (the generic version) instead, was correct.

There will be improved documentation around this topic.