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

GraphQLError: Cannot query field <FIELD> on type "Query" #648

Closed
janhartmann opened this issue Oct 30, 2018 · 2 comments
Closed

GraphQLError: Cannot query field <FIELD> on type "Query" #648

janhartmann opened this issue Oct 30, 2018 · 2 comments

Comments

@janhartmann
Copy link

After downloading my schema, I try to generate the TypeScript types using:

apollo codegen:generate  --schema=./src/data/schema.json --target=typescript

But this gives the following error:

$ apollo codegen:generate  --schema=./src/data/schema.json --target=typescript
 ✔ Loading Apollo config
 ✔ Scanning for GraphQL queries (663 found)
 ✖ Generating query files with 'typescript' target
   → Cannot query field "machines" on type "Query"
GraphQLError: Cannot query field "machines" on type "Query"
    at Compiler.compileSelection (~/Projects/manager-ui/node_modules/apollo-codegen-core/lib/compiler/index.js:120:27)
    at selections.selectionSetNode.selections.map.selectionNode (~/Projects/manager-ui/node_modules/apollo-codegen-core/lib/compiler/index.js:106:76)
    at Array.map (<anonymous>)
    at Compiler.compileSelectionSet (~/Projects/manager-ui/node_modules/apollo-codegen-core/lib/compiler/index.js:106:18)
    at Compiler.compileOperation (~/Projects/manager-ui/node_modules/apollo-codegen-core/lib/compiler/index.js:86:32)
    at Object.compileToIR (~/Projects/manager-ui/node_modules/apollo-codegen-core/lib/compiler/index.js:15:44)
    at Object.generate [as default] (~/Projects/manager-ui/node_modules/apollo/lib/generate.js:74:36)
    at Task.task (~/Projects/manager-ui/node_modules/apollo/lib/commands/codegen/generate.js:98:64)
    at Promise.resolve.then.then.skipped (~/Projects/manager-ui/node_modules/listr/lib/task.js:167:30)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I only have one GetMachines.graphql which is:

query GetMachines {
  machines {
    id
    name
  }
}

The generated schema.json contains this machines:

{
  "__schema": {
    "queryType": {
      "name": "Query"
    },
    "mutationType": {
      "name": "Mutation"
    },
    "subscriptionType": null,
    "types": [
      {
        "kind": "OBJECT",
        "name": "Query",
        "description": "",
        "fields": [
          {
            "name": "machines",
            "description": "",
            "args": [],
            "type": {
              "kind": "LIST",
              "name": null,
              "ofType": {
                "kind": "NON_NULL",
                "name": null,
                "ofType": {
                  "kind": "OBJECT",
                  "name": "Machine",
                  "ofType": null
                }
              }
            },
            "isDeprecated": false,
            "deprecationReason": null
          },
         ...
@janhartmann
Copy link
Author

I can resolve this issue by manually removing node_modules/apollo/node_modules/graphql directory. So it appears that the version of graphql (14.0.2) I am running is conflicting with Apollo CLI

@stevenpetryk
Copy link

Duplicate of #630 and #577 (fix is here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants