apollographql / apollographql/apollo-tooling

Error: Cannot use GraphQLNonNull "String!" from another module or realm.

Open
#2,674 3 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

**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

1. Create new Next.js Project

```shell
npx create-next-app --ts my-new-project
```

2. Create `apollo.config.js`

```js
module.exports = {
client: {
service: {
name : 'github',
url : 'https://api.github.com/graphql',
headers: {
authorization: 'Bearer my-secret-token',
},
},
},
};
```

2. Install Apollo Client: [Getting Started](https://www.apollographql.com/docs/react/get-started/#1-setup)

```shell
npm install @apollo/client graphql
```

3. Install Dependency `apollo`

```shell
npm install --save-dev apollo
```

Resulting `package.json` file

```json
{
"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"
}
}
```

4. Download Schema

```shell
apollo client:download-schema github-schema.graphql -c apollo.config.js
```

Resulting Error:

```shell
➜ 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.

1. Install Dependency `apollo`

```shell
npm install --save-dev apollo
```

2. Install Packages

```shell
npm install @apollo/client graphql
```

Resulting `package.json` file.

```json
{
"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`

3. Download Schema

```shell
apollo client:download-schema github-schema.graphql -c apollo.config.js
```

Resulting Error

```shell
➜ 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.

1. Install Dependency `apollo`

```shell
npm install --save-dev apollo
```

2. Install Packages

```shell
npm install @apollo/client graphql@latest
```

**NOTICE:** `graphql` is installed with `@latest` which is VERY IMPORTANT! But you will still get an warnings!!

```shell
➜ npm install @apollo/client graphql@latest
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @apollographql/graphql-language-service-interface@2.0.2
npm WARN Found: graphql@15.6.0
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/graphql-language-service-interface@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN @apollographql/graphql-language-service-interface@"^2.0.2" from apollo-language-server@1.26.4
npm WARN node_modules/apollo-language-server
npm WARN
npm WARN Conflicting peer dependency: graphql@14.7.0
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/graphql-language-service-interface@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN @apollographql/graphql-language-service-interface@"^2.0.2" from apollo-language-server@1.26.4
npm WARN node_modules/apollo-language-server
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @apollographql/graphql-language-service-parser@2.0.2
npm WARN Found: graphql@15.6.0
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/graphql-language-service-parser@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-parser
npm WARN @apollographql/graphql-language-service-parser@"^2.0.0" from @apollographql/graphql-language-service-interface@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN
npm WARN Conflicting peer dependency: graphql@14.7.0
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/graphql-language-service-parser@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-parser
npm WARN @apollographql/graphql-language-service-parser@"^2.0.0" from @apollographql/graphql-language-service-interface@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @apollographql/graphql-language-service-types@2.0.2
npm WARN Found: graphql@15.6.0
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/graphql-language-service-types@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-types
npm WARN @apollographql/graphql-language-service-types@"^2.0.0" from @apollographql/graphql-language-service-interface@2.0.2
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: graphql@14.7.0
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/graphql-language-service-types@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-types
npm WARN @apollographql/graphql-language-service-types@"^2.0.0" from @apollographql/graphql-language-service-interface@2.0.2
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/graphql-language-service-utils@2.0.2
npm WARN Found: graphql@15.6.0
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/graphql-language-service-utils@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-utils
npm WARN @apollographql/graphql-language-service-utils@"^2.0.2" from @apollographql/graphql-language-service-interface@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-interface
npm WARN
npm WARN Conflicting peer dependency: graphql@14.7.0
npm WARN node_modules/graphql
npm WARN peer graphql@"^0.12.0 || ^0.13.0 || ^14.0.0" from @apollographql/graphql-language-service-utils@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-utils
npm WARN @apollographql/graphql-language-service-utils@"^2.0.2" from @apollographql/graphql-language-service-interface@2.0.2
npm WARN node_modules/@apollographql/graphql-language-service-interface

added 15 packages, removed 1 package, changed 1 package, and audited 934 packages in 2s
```

3. Download Schema

```shell
apollo client:download-schema github-schema.graphql -c apollo.config.js
```

Resulting Output

```shell
➜ apollo client:download-schema github-schema.graphql -c apollo.config.js
✔ Loading Apollo Project
✔ Saving schema to github-schema.graphql
```

## SUCCESS!!!

**Versions**
```shell
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
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure in a new Next.js project using apollo.config.js, the listed package versions, and the apollo client:download-schema command. Inspect the installed GraphQL dependency versions and the Apollo CLI stack traces; done means the command saves github-schema.graphql without the reported module or realm errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, next.js, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.