cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety
https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/
MIT License
204 stars 25 forks source link

Error: Cannot use GraphQLSchema "[object GraphQLSchema]" from another module or realm. #120

Closed cometkim closed 2 years ago

cometkim commented 3 years ago
Error: Cannot use GraphQLSchema "[object GraphQLSchema]" from another module or realm.
  Ensure that there is only one instance of "graphql" in the node_modules
  directory. If different versions of "graphql" are the dependencies of other
  relied on modules, use "resolutions" to ensure only one version is installed.
  https://yarnpkg.com/en/docs/selective-version-resolutions
  Duplicate "graphql" modules cannot be used at the same time since different
  versions may have different capabilities and behavior. The data from one
  version used in the function from another could produce confusing and
  spurious results.

  - validate-documents.js:30
    /home/cometkim/Workspace/tmp/gatsby-plugin-typegen-114/.yarn/$$virtual/@graphql-tools-utils-virtual-addf5582c3/0/cache/@graphql-tools-utils-npm-6.2.4-2644cf0100-d773b36540.zip/dist/utils/src/validate-documents.js:30:24

  - Array.map

  - validate-documents.js:16 Object.validateGraphQlDocuments
    /home/cometkim/Workspace/tmp/gatsby-plugin-typegen-114/.yarn/$$virtual/@graphql-tools-utils-virtual-addf5582c3/0/cache/@graphql-tools-utils-npm-6.2.4-2644cf0100-d773b36540.zip/dist/utils/src/validate-documents.js:16:37

  - codegen.js:56 codegen
    /home/cometkim/Workspace/tmp/gatsby-plugin-typegen-114/.yarn/$$virtual/@graphql-codegen-core-virtual-29eca1d294/0/cache/@graphql-codegen-core-npm-1.17.8-309dc910b3-3bc9b4ff4b.zip/dist/graphql-codegen-core/src/codegen.js:56:30

  - codegen.js:128
    /home/cometkim/Workspace/tmp/gatsby-plugin-typegen-114/.yarn/$$virtual/gatsby-plugin-typegen-virtual-b6000e4cd7/3/src/github.com/cometkim/gatsby-plugin-typegen/plugin/workers/codegen.js:128:44

  - async.js:148
    [async-npm-3.2.0-b6fd825ddc-5c7913c084.zip]/[async]/dist/async.js:148:38

  - async.js:1427 Object.process
    [async-npm-3.2.0-b6fd825ddc-5c7913c084.zip]/[async]/dist/async.js:1427:21

  - async.js:1325
    [async-npm-3.2.0-b6fd825ddc-5c7913c084.zip]/[async]/dist/async.js:1325:19

  - async.js:321
    [async-npm-3.2.0-b6fd825ddc-5c7913c084.zip]/[async]/dist/async.js:321:20

  - async.js:179 invokeCallback
    [async-npm-3.2.0-b6fd825ddc-5c7913c084.zip]/[async]/dist/async.js:179:13

The first time to use this plugin, the user will encounter this problem.

This is because the Gatsby environment does not allow multiple versions of graphql to be loaded.

(Gatsby v2.24.* uses GraphQL v14.7.0, codegen/tools uses v15)

Fixing the GraphQL version to 14.7.0 via the yarn resolutions field can resolve this

{
  "resolutions": {
    "graphql": "14.7.0"
  }
}

However, the plugin should completely delegates schema handling to gatsby/graphql to get rid of this problem.

blurfx commented 3 years ago

if anyone is having this problem using Gatsby 3, fix the version of GraphQL to 15.3.0.

tested on Gatsby 3.6.2

cometkim commented 2 years ago

This can happen again anytime if there is a conflicting version of graphql-tools inside, and there doesn't seem to be any other way other than Yarn's resolutions when the problem arises.

(Unless https://github.com/ardatan/graphql-tools/issues/3599 come)

v3 uses dependencies as of Gatsby v4. (graphql@15)

Revisit the issue when using an older version or when a Gatsby v5 is released.