graphjin icon indicating copy to clipboard operation
graphjin copied to clipboard

Webshop example schema error with graphql-code-generator

Open rpham-eog opened this issue 2 years ago • 6 comments

What version of GraphJin are you using?

Latest master branch, v3.0.12 docker image

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

64 GB, macOS Monterey

Steps to reproduce the issue (config used to run GraphJin).

  1. Download https://github.com/dosco/graphjin/tree/f47065f9856ac1c81aef82dd78c557a53f4b0429/examples/webshop (latest example commit to master as of 7/6/2023 6:25 PM CDT)
  2. cd examples/webshop
  3. docker-compose run api db reset (Note: latest is used, which is currently equivalent to v3.0.12)
  4. docker-compose up
  5. Download this repo and run yarn codegen

Expected behaviour and actual result.

Code generation fails while loading schema. Expected to succeed without error.

Outputs the below error

rpham@hourpham-mb9DKD code-gen-test % yarn codegen
yarn run v1.22.19
$ graphql-codegen --config codegen.ts
✔ Parse Configuration
⚠ Generate outputs
  ❯ Generate to src/graphql/generated.ts
    ✖
      Failed to load schema from http://localhost:8080/api/v1/graphql:
      Schema must contain uniquely named types but contains multiple types named "rolesEnum".
      Error: Schema must contain uniquely named types but contains multiple types named "rolesEnum".
      at new GraphQLSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/graphql/type/schema.js:219:15)
      at mapSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/utils/cjs/mapSchema.js:14:12)
      at createWrappingSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/wrap/cjs/wrapSchema.js:16:34)
      at wrapSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/wrap/cjs/wrapSchema.js:11:20)
      at memoized (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/utils/cjs/memoize.js:9:30)
      at UrlLoader.load (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/url-loader/cjs/index.js:228:51)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/load/cjs/load-typedefs/load-file.js:15:39
      at async Promise.all (index 5)
      at async loadFile (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/load/cjs/load-typedefs/load-file.js:13:9)
      GraphQL Code Generator supports:
      - ES Modules and CommonJS exports (export as default or named export "schema")
      - Introspection JSON File
      - URL of GraphQL endpoint
      - Multiple files with type definitions (glob expression)
      - String in config file
      Try to use one of above options and run codegen again.
    ◼ Load GraphQL documents
    ◼ Generate
  ❯ Generate to src/graphql/graphql.schema.json
    ✖
      Failed to load schema from http://localhost:8080/api/v1/graphql:
      Schema must contain uniquely named types but contains multiple types named "rolesEnum".
      Error: Schema must contain uniquely named types but contains multiple types named "rolesEnum".
      at new GraphQLSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/graphql/type/schema.js:219:15)
      at mapSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/utils/cjs/mapSchema.js:14:12)
      at createWrappingSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/wrap/cjs/wrapSchema.js:16:34)
      at wrapSchema (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/wrap/cjs/wrapSchema.js:11:20)
      at memoized (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/utils/cjs/memoize.js:9:30)
      at UrlLoader.load (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/url-loader/cjs/index.js:228:51)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/load/cjs/load-typedefs/load-file.js:15:39
      at async Promise.all (index 5)
      at async loadFile (/Users/rpham/Documents/repos/code-gen-test/node_modules/@graphql-tools/load/cjs/load-typedefs/load-file.js:13:9)
      GraphQL Code Generator supports:
      - ES Modules and CommonJS exports (export as default or named export "schema")
      - Introspection JSON File
      - URL of GraphQL endpoint
      - Multiple files with type definitions (glob expression)
      - String in config file
      Try to use one of above options and run codegen again.
    ◼ Load GraphQL documents
    ◼ Generate
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

rpham-eog avatar Jul 06 '23 23:07 rpham-eog

I also received this error when using the /api/v1/graphql url with graphql-codegen but the intro.json file that's output by the enable_introspection: true config option worked for me.

https://graphjin.com/posts/cheatsheet#introspection-query

nathanstitt avatar Sep 21 '23 21:09 nathanstitt

I don't know much about graphql-codegen but this is wierd the intro.json is the same as whats sent via /api/v1/graphql so if one worked so should the other.

     Error: Schema must contain uniquely named types but contains multiple types named "rolesEnum".
     ```

dosco avatar Sep 23 '23 07:09 dosco

@dosco Yeah I have this error too, however if I point it to the generated intro.json it seems to work correctly. I think we need to figure out if the data thats being sent out is 100% the same. I'll look at this in a bit once I'm done building out the current MVP.

rkrishnasanka avatar Dec 14 '23 11:12 rkrishnasanka

bBest option is to save the two and do a diff on it. would love some help with this. The function used by both is gj.getIntroResult() it also caches the query so it should be the same. however just to be sure I'm moving the initial generation call lower in the init stack to be sure it's working with a fully initialized state.

dosco avatar Dec 14 '23 23:12 dosco

@dosco I'll check on this and give you an update. I'm just trying to get my prototype working this week.

rkrishnasanka avatar Dec 15 '23 09:12 rkrishnasanka

@dosco looking at how the responses are coming out, it seems like the only difference between the responses are: having the extra "data" wrappering the graph query response. But when I run the same wrappered json via the file schema option, it works. This is an issue with the codegen tool and not graphjin.

Screen Shot 2023-12-15 at 4 21 32 PM

rkrishnasanka avatar Dec 15 '23 11:12 rkrishnasanka