Ensure that there is only one instance of "graphql" in the node_modules directory
Asked Answered
O

2

6

While trying to download the schema using npm run schema:download I am receiving the following error.

[email protected] schema:download npx apollo service:download --endpoint=http://localhost:9000/graphql ./src/app/graphql-schema.json


DEPRECATED: This command will be removed from the apollo CLI in its next major version. Replacement functionality is available in the new Apollo Rover CLI: https://go.apollo.dev/t/migration

✔ Loading Apollo Project ✖ Saving schema to ./src/app/graphql-schema.json → spurious results. Error: Cannot use GraphQLSchema "{ __validationErrors: undefined, extensions: undefined, astNode: undefined, extensionASTNodes: undefined, __allowedLegacyNames: [], _queryType: Query, _mutationType: Mutation, _subscriptionType: null, _directives: [@include, @skip, @deprecated, @specifiedBy], _typeMap: { Query: Query, Car: Car, String: String, Float: Float, Mutation: Mutation, NewCarInput: NewCarInput, Int: Int, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, Boolean: Boolean, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _possibleTypeMap: {}, _implementations: {} }" 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.

I have provided the endpoint for schema:download in my package.json as below.

  "scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"schema:download": "npx apollo service:download --endpoint=http://localhost:9000/graphql ./src/app/graphql-schema.json",
"schema:generate-watch": "npx apollo codegen:generate --localSchemaFile=./src/app/graphql-schema.json --target=typescript --tagName=gql --watch"

},

Can somebody help me sort out with the issue as Im new to graphql

Oath answered 25/9, 2021 at 4:58 Comment(0)
B
5

I switched graphql to v15.7.2 in package.json and it works for me.

Beardless answered 28/12, 2021 at 10:47 Comment(1)
Version 15 worked for me, where 14 and 16 doesn't, thanks!Neat
A
0

In my case, the problem was that I also had graphql installed globally. Removing it fixed the error:

yarn global remove graphql

The npm equivalent would be:

npm uninstall -g graphql

Just be careful you're not depending on that global installation for something else on your system.

Ankh answered 20/4, 2022 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.