Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some kind of conflict with graphql-js 14.0.0 #577

Closed
Slessi opened this issue Sep 4, 2018 · 11 comments
Closed

Some kind of conflict with graphql-js 14.0.0 #577

Slessi opened this issue Sep 4, 2018 · 11 comments
Labels
🌹 has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository

Comments

@Slessi
Copy link

Slessi commented Sep 4, 2018

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.

@ghost ghost added the blocking label Sep 4, 2018
@ravangen
Copy link

ravangen commented Sep 4, 2018

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".

@Slessi
Copy link
Author

Slessi commented Sep 4, 2018

@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.

@PhilippSpo
Copy link

PhilippSpo commented Sep 5, 2018

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.

@ksmth
Copy link

ksmth commented Sep 12, 2018

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.

@randyridge
Copy link

randyridge commented Sep 13, 2018

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.

@ZenSoftware
Copy link

ZenSoftware commented Sep 15, 2018

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.

esamattis referenced this issue in esamattis/wp-graphql-todoapp Sep 16, 2018
@Slessi
Copy link
Author

Slessi commented Sep 17, 2018

@ghost ghost added blocking 🌹 has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository labels Sep 17, 2018
@stnwk
Copy link
Contributor

stnwk commented Sep 27, 2018

  "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..

@jariz
Copy link

jariz commented Oct 2, 2018

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".

@ZenSoftware
Copy link

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.

@Slessi
Copy link
Author

Slessi commented Oct 15, 2018

#624 Should resolve this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌹 has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants