apollo-tooling: error: Validation of GraphQL query document failed

  • npm install -g apollo-codegen
  • schema.graphql
  • apollo-codegen introspect-schema schema.graphql --output schema.json
  • apollo-codegen generate **/*.graphql --schema schema.json --target typescript --output operation-result-types.ts
.../ivan/github/demo/schema.graphql: The Comment definition is not executable.
.../ivan/github/demo/schema.graphql: The ContentFormatEnum definition is not executable.
.../ivan/github/demo/schema.graphql: The Email definition is not executable.
.../ivan/github/demo/schema.graphql: The ImageSizeEnum definition is not executable.
.../ivan/github/demo/schema.graphql: The ImageType definition is not executable.
.../ivan/github/demo/schema.graphql: The ImageTypeEnum definition is not executable.
.../ivan/github/demo/schema.graphql: The Node definition is not executable.
.../ivan/github/demo/schema.graphql: The Query definition is not executable.
.../ivan/github/demo/schema.graphql: The SearchResultType definition is not executable.
.../ivan/github/demo/schema.graphql: The Story definition is not executable.
.../ivan/github/demo/schema.graphql: The StoryAffordancesEnum definition is not executable.
.../ivan/github/demo/schema.graphql: The Url definition is not executable.
.../ivan/github/demo/schema.graphql: The User definition is not executable.
error: Validation of GraphQL query document failed

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 31
  • Comments: 25 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I think the confusion here is that some people (myself included) want typescript interfaces for all the types in the graphql schema, not just for the query and mutation operations used by the client. That way we can use generated types on the server-side to add types to our resolvers. Not sure if there is a tool out there that does this?

Edit: https://github.com/dotansimha/graphql-code-generator

I found that i was using what apollo considers anonymous operation. Which i fixed by adding a name to the query.

Before

query {
  example {
    id
  }
}

After

query Example{
  example {
    id
  }
}

@ibigpapa This was a shocking experience, I’ve just wasted three hours of my life until I found your hint. Would it be possible to improve the error message “Validation of GraphQL query document failed” to give some hints about the problem.

facing the same issue as @alonstar introduced… Can someone clarify the way of using codegen, please?

You have to make sure that schema.graphql is not part of the files that are treated as query documents. With **/*.graphql, all .graphql files will be selected, so you should probably make that more specific and/or move the schema file.

@alonstar I have tried the same steps that you, but I have noticed that this tool is to generate a file of types from different querys of grahpql.

This works for me

  1. npm install -g apollo-codegen
  2. apollo-codegen introspect-schema http://localhost:13083/graphql --output schema.json
  3. wirte custom query file getCategory.graphql
query getCategory{
  category(id: 1) {
    name
  }
}
  1. apollo-codegen generate getCategory.graphql --schema schema.json --target flow --output graphql.flow.js the output it’s like this
export type getCategoryQuery = {|
  category: ? {|
    name: ?string,
  |},
|};
  1. Use this types in your code
// @flow
import ApolloClient from 'apollo-boost'
import gql from 'graphql-tag'
import type { getCategoryQuery } from "./graphql.flow.js"
const client = new ApolloClient()

export const fetchCategory = (id: number) => (
  client.query({
    query: gql`{
      category(id: ${id}) {
        name
      }
    }
  `}): Promise<{
    data: getCategoryQuery;
  }>
)

Now for the function fetchCategory the autocomplete or types validations works

@triedal It‘s the same error as the OP has. Make sure you do not include your schema file (user.graphql) into the apollo-codegen glob