apollo-tooling
apollo-tooling copied to clipboard
Error: Cannot use GraphQLNonNull "String!" from another module or realm.
Intended outcome: Connect to and generate schema from GitHub.
Actual outcome: Dependency conflicts shown in error reproduction errors.
How to reproduce the issue: Working on a new Next.js project and get an error:
Error: Cannot use GraphQLNonNull "String!" from another module or realm.
There appears to be a solution in the way npm
packages are installed. Below are the steps to reproduce the issue and apparently solve the problem.
Steps to Reproduce: ERROR NO: 1
- Create new Next.js Project
npx create-next-app --ts my-new-project
- Create
apollo.config.js
module.exports = {
client: {
service: {
name : 'github',
url : 'https://api.github.com/graphql',
headers: {
authorization: 'Bearer my-secret-token',
},
},
},
};
- Install Apollo Client: Getting Started
npm install @apollo/client graphql
- Install Dependency
apollo
npm install --save-dev apollo
Resulting package.json
file
{
"dependencies" : {
"@apollo/client": "^3.4.15",
"graphql" : "^15.6.0",
"next" : "11.1.2",
"react" : "17.0.2",
"react-dom" : "17.0.2"
},
"devDependencies": {
"@types/react" : "17.0.26",
"apollo" : "^2.33.6",
"eslint" : "7.32.0",
"eslint-config-next": "11.1.2",
"typescript" : "4.4.3"
}
}
- Download Schema
apollo client:download-schema github-schema.graphql -c apollo.config.js
Resulting Error:
➜ apollo client:download-schema github-schema.graphql -c apollo.config.js
✔ Loading Apollo Project
✖ Saving schema to github-schema.graphql
→ spurious results.
Error: Cannot use GraphQLNonNull "String!" 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.
Steps to Reproduce: ERROR NO: 2
apollo.config.js
continues to exist.
- Install Dependency
apollo
npm install --save-dev apollo
- Install Packages
npm install @apollo/client graphql
Resulting package.json
file.
{
"dependencies": {
"@apollo/client": "^3.4.15",
"graphql": "^14.7.0",
"next": "11.1.2",
"react": "17.0.2",
"react-dom": "17.0.2"
},
"devDependencies": {
"@types/react": "17.0.26",
"apollo": "^2.33.6",
"eslint": "7.32.0",
"eslint-config-next": "11.1.2",
"typescript": "4.4.3"
}
}
graphql DIFFERENCE!!
First attempt version install is ^15.6.0
and second attempt is ^14.7.0
- Download Schema
apollo client:download-schema github-schema.graphql -c apollo.config.js
Resulting Error
➜ apollo client:download-schema github-schema.graphql -c apollo.config.js
Error: Cannot find module 'graphql/validation/rules/KnownArgumentNamesRule'
Require stack:
- /home/edwinvelez/Downloads/my-new-project/node_modules/@apollo/federation/dist/composition/validate/preNormalization/tagDirect
ive.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@apollo/federation/dist/composition/validate/preNormalization/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@apollo/federation/dist/composition/validate/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@apollo/federation/dist/composition/composeAndValidate.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@apollo/federation/dist/composition/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@apollo/federation/dist/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/apollo-language-server/lib/providers/schema/file.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/apollo-language-server/lib/providers/schema/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/apollo-language-server/lib/project/base.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/apollo-language-server/lib/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/apollo/lib/Command.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/apollo/lib/commands/client/download-schema.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@oclif/config/lib/plugin.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@oclif/config/lib/config.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@oclif/config/lib/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@oclif/command/lib/command.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/@oclif/command/lib/index.js
- /home/edwinvelez/Downloads/my-new-project/node_modules/apollo/bin/run
Code: MODULE_NOT_FOUND
Solution to Correct Problem
Change the order of package installation.
- Install Dependency
apollo
npm install --save-dev apollo
- Install Packages
npm install @apollo/client graphql@latest
NOTICE: graphql
is installed with @latest
which is VERY IMPORTANT! But you will still get an warnings!!
➜ npm install @apollo/client graphql@latest
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @apollographql/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/graphql
npm WARN graphql@"15.6.0" from the root project
npm WARN 12 more (@apollo/federation, apollo, apollo-graphql, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer graphql@"^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN @apollographql/graphql-language-service-interface@"^2.0.2" from [email protected]
npm WARN node_modules/apollo-language-server
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/graphql
npm WARN peer graphql@"^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN @apollographql/graphql-language-service-interface@"^2.0.2" from [email protected]
npm WARN node_modules/apollo-language-server
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @apollographql/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/graphql
npm WARN graphql@"15.6.0" from the root project
npm WARN 12 more (@apollo/federation, apollo, apollo-graphql, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer graphql@"^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-parser
npm WARN @apollographql/graphql-language-service-parser@"^2.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/graphql
npm WARN peer graphql@"^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-parser
npm WARN @apollographql/graphql-language-service-parser@"^2.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @apollographql/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/graphql
npm WARN graphql@"15.6.0" from the root project
npm WARN 12 more (@apollo/federation, apollo, apollo-graphql, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer graphql@"^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-types
npm WARN @apollographql/graphql-language-service-types@"^2.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN 2 more (@apollographql/graphql-language-service-parser, @apollographql/graphql-language-service-utils)
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/graphql
npm WARN peer graphql@"^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-types
npm WARN @apollographql/graphql-language-service-types@"^2.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN 2 more (@apollographql/graphql-language-service-parser, @apollographql/graphql-language-service-utils)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @apollographql/[email protected]
npm WARN Found: [email protected]
npm WARN node_modules/graphql
npm WARN graphql@"15.6.0" from the root project
npm WARN 12 more (@apollo/federation, apollo, apollo-graphql, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer graphql@"^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-utils
npm WARN @apollographql/graphql-language-service-utils@"^2.0.2" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/graphql
npm WARN peer graphql@"^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-utils
npm WARN @apollographql/graphql-language-service-utils@"^2.0.2" from @apollographql/[email protected]
npm WARN node_modules/@apollographql/graphql-language-service-interface
added 15 packages, removed 1 package, changed 1 package, and audited 934 packages in 2s
- Download Schema
apollo client:download-schema github-schema.graphql -c apollo.config.js
Resulting Output
➜ apollo client:download-schema github-schema.graphql -c apollo.config.js
✔ Loading Apollo Project
✔ Saving schema to github-schema.graphql
SUCCESS!!!
Versions
System:
OS: Linux 5.14 Arch Linux
Binaries:
Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
Yarn: 1.22.15 - ~/Downloads/my-new-project/node_modules/.bin/yarn
npm: 7.24.1 - ~/.nvm/versions/node/v14.17.6/bin/npm
npmPackages:
@apollo/client: ^3.4.15 => 3.4.15
apollo: ^2.33.6 => 2.33.6
The problem here is the apollo
cli package, which is not in a very good state. At the moment the apollo
package has some dependencies which are not compatible with graphql >=15, and other dependencies which are not compatible with graphql <=14. It looks like maintenance on this package has slowed down a lot. I personally recommend you try GraphQL Code Generator instead of the apollo cli.
See more here:
https://github.com/apollographql/apollo-tooling/issues/2415
https://github.com/apollographql/apollo-tooling/issues/2232
Hey @dylanwulf.
I was wondering if I would ever get a reply to this. But only yesterday, when on my phone via the GitHub app, did I accidentally close and then reopen this issue. Looks like doing so put this back in view.
Anyways, I was not aware of the maintenance as you described but thank you for the info. And yes.......GraphQL Code Generator seems to be a much better solution. Thanks for your reply and guidance.
Also got this problem at the moment. Still no fixes for that?