apollo-tooling: 2.12.3: Error: Cannot use GraphQLSchema "[object GraphQLSchema]" from another module or realm
After upgrading from apollo@2.12.2
--> apollo@2.12.3
, I started receiving the following error while trying to download my schema:
> apollo service:download --endpoint=$API_ENDPOINT_PROXY/v2/graphql graphql-schema.json
✔ Loading Apollo Project
✖ Saving schema to graphql-schema.json
→ spurious results.
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.
at instanceOf (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/jsutils/instanceOf.js:37:13)
at isSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/schema.js:34:34)
at assertSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/schema.js:38:4)
at validateSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/validate.js:53:28)
at assertValidSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/validate.js:77:16)
at assertValidExecutionArguments (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/execution/execute.js:146:35)
at executeImpl (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/execution/execute.js:67:3)
at execute (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/execution/execute.js:62:256)
at Object.introspectionFromSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/utilities/introspectionFromSchema.js:38:37)
at Task.task (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/lib/commands/service/download.js:21:82)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! mmdp-app@0.0.7 update:schema: `apollo service:download --endpoint=$API_ENDPOINT_PROXY/v2/graphql graphql-schema.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the mmdp-app@0.0.7 update:schema script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/joncursi/.npm/_logs/2019-05-23T20_52_56_722Z-debug.log
ERROR: "update:schema" exited with 2.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mmdp-app@0.0.7 update: `dotenv -e .env -- npm-run-all update:schema update:types`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mmdp-app@0.0.7 update script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/joncursi/.npm/_logs/2019-05-23T20_52_56_754Z-debug.log
Downgrading back to 2.12.2
causes the error to go away.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 28
- Comments: 22
If you are using npm:
node_modules/apollo/package.json
"graphql": "~14.2.1
package.json
to make sure it matches exactly what apollo is usingrm -rf node_modules/
npm i
npm dedupe
Yup, and all sort of others things like burning sand in a cup shouting chinese words but no success…
Just to add on here, I was able to do what @xsats did, but using “graphql”: “^15.0.0”. There was no need to downgrade the version. All I did was
In case anyone has a variable version like this
14.0.2 - 14.2.0 || ^14.3.1
,:packadge.json
and innode_modules/apollo/packadge.json
node_modules/apollo/node_modules
node_modules/apollo/
node_modules/apollo/
I changed my backend’s folder structure around and started getting this error while using serverless-offline and refreshing the local version of my UI. The fix for me was to change this line in my webpack config
externals: [ nodeExternals() ],
to
externals: [ nodeExternals({ modulesDir: path.resolve(__dirname, 'node_modules') }) ],
This fix probably doesn’t apply to you if you are using a standard folder structure. I don’t even know why this worked.
This still seems to be an issue, should we re-open?
This is not a fix as it doesn’t work lol, i don’t even remember exactly but it’s like putting graphql with a precise version in the
resolutions
field of the package.jsonI made my own tools
Nop it’s not possible, neither to
link
other project usingGraphql.js
this realm security is imo useless and makes things overcomplex, i resolved it by refactoring my whole monorepo to import ‘graphql’ in only one place. Note that this security also prevent us from using a commonjs library that use graphql & using it ourselve through esm, that said i also moved away from all that heavy apollo stuff which has enough line of code to sink the earth into a black hole 😁 good luck my friend, i opted to write my own graphql solution on top of the graphqljs lib@amritk This is still an issue for me as well.
I am unable to understand where this error comes from…
My command:
apollo codegen:generate -c apollo.config.js --target typescript --excludes=node_modules/* --includes=./src/apollo/queries/*.ts --tagName=gql --outputFlat src/graphql-schema
The error:
My graphql dependencies:
All use graphql@15.8.0 except some sub-dependencies of
apollo
To onlookers facing a similar problem, I ended up adding yarn resolutions to the base package.json in my yarn workspaces monorepo, specifying a version of GraphQL that previously worked fine.
‘“resolutions”: { “graphql”: “^14.3.2” }"’
This fully resolved the duplicate GraphQL dependency error above.