Graphql-code-generator: Fails to load schema (worked before update)

Created on 3 Feb 2020  ·  7Comments  ·  Source: dotansimha/graphql-code-generator

Describe the bug

Fails to correctly resolve a field that is defined in another file.

$ graphql-codegen --config codegen.yml
  ✔ Parse configuration
  ❯ Generate outputs
    ❯ Generate ./src/schemaTypes.d.ts
      ✖ Load GraphQL schemas
        → Failed to load schema
        Load GraphQL documents
        Generate


 Found 1 error

  ✖ ./src/schemaTypes.d.ts
    Failed to load schema from schemas/*.graphql:

        Field user: Couldn't find type User in any of the schemas.
        Error: Field user: Couldn't find type User in any of the schemas.

To Reproduce
Steps to reproduce the behaviour:

This one was a really hard one to reproduce. But I have now copied 'enough' of my repository to codesandbox such that it reproduces the issue.

Find the reproduced bug here on Codesandbox

NOTE I only started getting this error when upgrading from 1.11.2 to 1.12.1.

$ git diff yarn.lock | grep codegen
+    "@protobufjs/codegen" "^2.0.4"
 "@graphql-codegen/cli@^1.11.2":
-  resolved "https://registry.yarnpkg.com/@graphql-codegen/cli/-/cli-1.11.2.tgz#a1d4ef8d06b692c37c5efc686976ec2eedefa4fe"
-    "@graphql-codegen/core" "1.11.2"
-    "@graphql-codegen/plugin-helpers" "1.11.2"
+  resolved "https://registry.yarnpkg.com/@graphql-codegen/cli/-/cli-1.12.1.tgz#7d7535f0dc6f12285ec987dd7b734de5e5395f67"
+    "@graphql-codegen/core" "1.12.1"
+    "@graphql-codegen/plugin-helpers" "1.12.1"
-"@graphql-codegen/[email protected]":
-  resolved "https://registry.yarnpkg.com/@graphql-codegen/core/-/core-1.11.2.tgz#aa3e0ad60b8ccf72d73ec6f16198ee6ef02e7b56"
+"@graphql-codegen/[email protected]":
+  resolved "https://registry.yarnpkg.com/@graphql-codegen/core/-/core-1.12.1.tgz#fd6ee38ff5ee1665051051f115d4a4ab0b3718f3"
-    "@graphql-codegen/plugin-helpers" "1.11.2"
+    "@graphql-codegen/plugin-helpers" "1.12.1"
 "@graphql-codegen/[email protected]":
+"@graphql-codegen/[email protected]":
+  resolved "https://registry.yarnpkg.com/@graphql-codegen/plugin-helpers/-/plugin-helpers-1.12.1.tgz#6fff6bbc1853a4024ff968bb3edd8750f7ea1244"
 "@graphql-codegen/[email protected]":
   resolved "https://registry.yarnpkg.com/@graphql-codegen/typescript-mongodb/-/typescript-mongodb-1.11.2.tgz#fedc1cbb10e70071dc12cd706743b545ba5b0049"
 "@protobufjs/codegen@^2.0.4":
-  resolved "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz#7ef37f0d010fb028ad1ad59722e506d9262815cb"
+  resolved "https://registry.yarnpkg.com/@protobufjs/codegen/-/codegen-2.0.4.tgz#7ef37f0d010fb028ad1ad59722e506d9262815cb"
 escodegen@^1.9.1:
-  resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.12.1.tgz#08770602a74ac34c7a90ca9229e7d51e379abc76"
+  resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.13.0.tgz#c7adf9bd3f3cc675bb752f202f79a720189cab29"
-    "@protobufjs/codegen" "^2.0.4"

  1. My GraphQL schema:

It's best seen in the Codesandbox

  1. My GraphQL operations:
# Put your operations here
  1. My codegen.yml config file:
overwrite: true
schema: "schemas/*.graphql"
documents: null
generates:
    ./src/schemaTypes.d.ts:
        plugins:
            - "typescript"
            - "typescript-resolvers"
            - "typescript-mongodb"

Expected behavior

For this to generate. It worked correctly on the slightly older version (1.11.2). I am therefore stuck on this slightly older version.

Environment:

My local dev environment (not Codesandbox)

  • OS: macOS (although reproduced through Codesandbox - Linux)
  • @graphql-codegen/...:
  • NodeJS: 10.15.3

Additional context

bug core

Most helpful comment

@nebbles You are having the same issue as @smykhailov .
You need to pin, or align all your codegen dependencies. Either use ^version or just version, because otherwise you'll get a mixup of dependencies, and it will cause multiple versions of codegen core package.

I tested both solutions on your repo and it works. Also tested latest codegen version and it also works.

Closing.

If someone else is having this issue or similar - first, align you codegen versions is package.json :)

All 7 comments

@ardatan can you please take a look?

Same here, downgrading back to 1.8.3 worked for me.

Very strange error, I got the same and found the fix
instead of

    "@graphql-codegen/cli": "^1.11.2",
    "@graphql-codegen/introspection": "1.11.2",
    "@graphql-codegen/typescript": "1.11.2",
    "@graphql-codegen/typescript-mongodb": "1.11.2",
    "@graphql-codegen/typescript-resolvers": "1.11.2",

I changed the versions to:

    "@graphql-codegen/cli": "^1.11.2",
    "@graphql-codegen/introspection": "^1.11.2",
    "@graphql-codegen/typescript": "^1.11.2",
    "@graphql-codegen/typescript-mongodb": "^1.11.2",
    "@graphql-codegen/typescript-resolvers": "^1.11.2",

I didn't dig to root cause, but hope it will help in investigation

@smykhailov All you version should be either pinned or not, otherwise you risk in missmatch and duplicate packages.

@nebbles You are having the same issue as @smykhailov .
You need to pin, or align all your codegen dependencies. Either use ^version or just version, because otherwise you'll get a mixup of dependencies, and it will cause multiple versions of codegen core package.

I tested both solutions on your repo and it works. Also tested latest codegen version and it also works.

Closing.

If someone else is having this issue or similar - first, align you codegen versions is package.json :)

Thanks @dotansimha! Not sure how they got out of sync with only one defining a ^version. Everything back and working 🙏

For those who were still having issues, my problem was that I changed the port my backend instance was running on so it couldn't find my /graphql endpoint. I fixed the URL and it got fixed.

Was this page helpful?
0 / 5 - 0 ratings