Documentation
Parser Options

Parser Options

graphQLParserOptions

With this configuration, you can specify custom configurations for GraphQL’s parse method. By default, graphql-eslint parser just adds noLocation: false to make sure all parsed AST has location set, since we need this for tokenizing and for converting the GraphQL AST into ESTree.

You can find the complete set of options for this object here.

skipGraphQLConfig

If you are using graphql-config in your project, the parser will automatically use that to load your default GraphQL schema.

You can disable this behaviour using skipGraphQLConfig: true in the parserOptions:

.eslintrc.json
{
  "parserOptions": {
    "skipGraphQLConfig": true
  }
}

schema

You can specify parserOptions.schema to load your GraphQL schema. The parser uses graphql-tools and it’s loaders, that means you can either specify a URL, a path to a local .json (introspection) file, or a path to a local .graphql file(s). You can also use Glob expressions to load multiple files.

Here are a few examples for a valid setup:

.eslintrc.json
{
  "parserOptions": {
    "schema": "./schema.graphql"
  }
}
.eslintrc.json
{
  "parserOptions": {
    "schema": "./schema.json"
  }
}
.eslintrc.json
{
  "parserOptions": {
    "schema": "http://my-server/graphql"
  }
}
.eslintrc.json
{
  "parserOptions": {
    "schema": "./src/**/*.graphql"
  }
}
.eslintrc.json
{
  "parserOptions": {
    "schema": ["src/schema-a.graphql", "src/schema-b.graphql", "src/schema-c.graphql"]
  }
}

schemaOptions

If you wish to send additional configuration for the graphql-tools loaders that loads your schema, you can specify schemaOptions object:

.eslintrc.json
{
  "parserOptions": {
    "schema": "http://my-server/graphql",
    "schemaOptions": {
      "headers": {
        "Authorization": "Bearer MY_TOKEN"
      }
    }
  }
}
.eslintrc.json
{
  "parserOptions": {
    "schema": "./src/**/*.graphql",
    "schemaOptions": {
      "assumeValid": true
    }
  }
}
💡

The configuration here is flexible, and will be sent to graphql-tools and it’s loaders. So depends on the schema source, the options may vary.

You can read more about these loaders and their configuration here.