Apollo-tooling: Some kind of conflict with graphql-js 14.0.0

Created on 4 Sep 2018  ยท  11Comments  ยท  Source: apollographql/apollo-tooling

Minimal repro here: https://github.com/Slessi/apollo-minimal-repro

Using apollo cli (tried 1.7.1 and 1.9.1) with graphql-js 14.0.0 doesn't seem to work for generating queries.

Generating schema still ok.

OK:

apollo schema:download --endpoint=http://localhost:4000/graphql schema.json

 โœ” Loading Apollo config
 โœ” Fetching current schema
 โœ” Saving schema to schema.json

NOT OK:

Note: I am not actually trying to query __typename in my .graphql

apollo codegen:generate --queries=src/**/*.graphql --schema=schema.json --target=typescript --addTypename --customScalarsPrefix=\"GQL\" --outputFlat src/components/GraphQL/types.ts

 โœ” Loading Apollo config
 โœ” Scanning for GraphQL queries (48 found)
 โœ– Generating query files with 'typescript' target
   โ†’ Cannot query field "__typename" on type "User"
GraphQLError: Cannot query field "__typename" on type "User"
    at Compiler.compileSelection (~/<proj>/node_modules/apollo-codegen-core/lib/compiler/index.js:120:27)
    at selections.selectionSetNode.selections.map.selectionNode (~/<proj>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:76)
    at Array.map (<anonymous>)
    at Compiler.compileSelectionSet (~/<proj>/node_modules/apollo-codegen-core/lib/compiler/index.js:106:18)
    at Compiler.compileFragment (~/<proj>/node_modules/apollo-codegen-core/lib/compiler/index.js:99:32)
    at Object.compileToIR (~/<proj>/node_modules/apollo-codegen-core/lib/compiler/index.js:19:43)
    at Object.generate [as default] (~/<proj>/node_modules/apollo/lib/generate.js:74:36)
    at Task.task (~/<proj>/node_modules/apollo/lib/commands/codegen/generate.js:98:64)
    at Promise.resolve.then.then.skipped (~/<proj>/node_modules/listr/lib/task.js:167:30)
    at <anonymous>

The problem begins when my project requires 14.0.0.

I can "fix" the problem by deleting node_modules/apollo/node_modules/graphql/ as the library then uses node_modules/graphql, which is 14.0.0, so maybe just needs a version bump? Don't understand why there would be a problem when both versions exist.

has-reproduction

Most helpful comment

  "resolutions": {
    "@types/graphql": "14.0.1", /* typescript only */
    "graphql": "14.0.2"
  }

Adding this to my package.json fixed it for me temporarily until the dependencies get updated here..

All 11 comments

Given you say you are not trying to query with __typename, and it is causing a problem, you can try removing --addTypename from the command you are running. Its presence will "Automatically add __typename to your queries".

@ravangen I know what it does and I need it, just saying that I'm not adding it as a field in any .graphql queries.

Anyway, removing it just changes the error to something else. Still doesn't work.

I have the same issue. Only for fragments though. When I remove the fragments I get this error message, which I think is the actual problem:

Error: Cannot use GraphQLScalarType "ID" 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 guess this means that apollo needs to upgrade to [email protected] in order for this to work.

The version doesn't appear to matter. My main module depends on [email protected] and this appears to be the same as the current apollo. When I remove apollo/node_modules/graphql, everything works as expected.

I also have same issue with apollo 1.9.1 and 1.9.2 and gql 14.0.x, reverting to 0.13.2 resolves:

rimraf ./node_modules/.cache&&apollo schema:download --endpoint=https://someserver/graphql ./gql/schema.json&&node ./gql/buildFragments&&apollo codegen:generate --queries=**/*.gql --schema=./gql/schema.json --mergeInFieldsFromFragmentSpreads --target=typescript --addTypename --outputFlat ./gql/schema.ts
โˆš Loading Apollo config โˆš Fetching current schema โˆš Saving schema to ./gql/schema.json Fragment types successfully extracted! โˆš Loading Apollo config โˆš Scanning for GraphQL queries (5 found) ร— Generating query files with 'typescript' target โ†’ Cannot query field "someField" on type "Query" GraphQLError: Cannot query field "someField" on type "Query" at Compiler.compileSelection (./node_modules/apollo-codegen-core/lib/compiler/index.js:120:27) at selections.selectionSetNode.selections.map.selectionNode (./node_modules/apollo-codegen-core/lib/compiler/index.js:106:76) at Array.map (<anonymous>) at Compiler.compileSelectionSet (./node_modules/apollo-codegen-core/lib/compiler/index.js:106:18) at Compiler.compileOperation (./node_modules/apollo-codegen-core/lib/compiler/index.js:86:32) at Object.compileToIR (./node_modules/apollo-codegen-core/lib/compiler/index.js:15:44) at Object.generate [as default] (./node_modules/apollo/lib/generate.js:74:36) at Task.task (./node_modules/apollo/lib/commands/codegen/generate.js:98:64) at Promise.resolve.then.then.skipped (./node_modules/listr/lib/task.js:167:30) error Command failed with exit code 1.

I get the following error when using the command apollo codegen:generate after upgrading from graphql 0.13.2 to 14.0.0. Reverting to [email protected] resolves the issue.

Error: Command failed: apollo codegen:generate codegen-types.ts --outputFlat --addTypename --schema="schema.json" --queries="apps\**\*.{gql,graphql}"
Error: Cannot use GraphQLInputObjectType "RegistrationInput" 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.
  "resolutions": {
    "@types/graphql": "14.0.1", /* typescript only */
    "graphql": "14.0.2"
  }

Adding this to my package.json fixed it for me temporarily until the dependencies get updated here..

Not being able to support GQL 0.14 is understandable, but at least update the 'quick' setup guide to indicate that apollo only works with 0.13 at the moment and that people need to npm i [email protected].
Just wasted an entire day because I kept pointing the finger back at myself thinking "no, their guide can't possibly be broken".

I can confirm that deleting the folder node_modules/apollo/node_modules/graphql resolves my error that reads:
Ensure that there is only one instance of "graphql" in the node_modules directory.

I looked at the dependencies for the apollo package and see that it is using "graphql": "^0.13.2"
It needs the dependency to be bumped to "graphql": "^14.0.0" to get rid of duplicate graphql instances.

624 Should resolve this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

viridia picture viridia  ยท  3Comments

fenech picture fenech  ยท  3Comments

pietmichal picture pietmichal  ยท  4Comments

rasmusprentow picture rasmusprentow  ยท  3Comments

hashlin picture hashlin  ยท  4Comments