On this page

Usage to lint different schemas

Usage to lint different schemas — GraphQL ESLint documentation.

GraphQL Config

graphql.config.ts
import type { GraphQLTagPluckOptions, IGraphQLConfig } from '@graphql-eslint/eslint-plugin'

const config: IGraphQLConfig = {
  projects: {
    firstProject: {
      schema: 'schema.first-project.graphql',
      documents: 'query.first-project.js'
    },
    secondProject: {
      schema: 'schema.second-project.graphql',
      documents: 'query.second-project.js',
      extensions: {
        // in case you want to use different names for magic comment and module identifier
        pluckConfig: {
          modules: [{ name: 'custom-graphql-tag', identifier: 'custom' }],
          globalGqlIdentifierName: 'custom',
          gqlMagicComment: 'MyGraphQL'
        } satisfies GraphQLTagPluckOptions
      }
    }
  }
}

export default config

ESLint Flat Config

eslint.config.js
import js from '@eslint/js'
import graphqlPlugin from '@graphql-eslint/eslint-plugin'

export default [
  {
    files: ['**/*.js'],
    processor: graphqlPlugin.processor,
    rules: js.configs.recommended.rules
  },
  {
    // Setup GraphQL Parser
    files: ['**/*.graphql'],
    languageOptions: {
      parser: graphqlPlugin.parser
    },
    plugins: {
      '@graphql-eslint': graphqlPlugin
    }
  },
  {
    files: ['schema.*.graphql'],
    rules: {
      ...graphqlPlugin.configs['flat/schema-recommended'].rules,
      '@graphql-eslint/require-description': 'off'
    }
  },
  {
    files: ['**/*.js/*.graphql'],
    rules: graphqlPlugin.configs['flat/operations-recommended'].rules
  }
]

ESLint Legacy Config

.eslintrc.cjs
/**
 * Legacy config example, should be run with `ESLINT_USE_FLAT_CONFIG=false` environment variable in ESLint 9
 */

module.exports = {
  root: true,
  // ❗️ It's very important that you don't have any rules configured at the top-level config,
  // and to move all configurations into the overrides section. Since JavaScript rules
  // can't run on GraphQL files and vice versa, if you have rules configured at the top level,
  // they will try to also execute for all overrides, as ESLint's configs cascade
  overrides: [
    {
      files: ['*.js'],
      processor: '@graphql-eslint/graphql',
      extends: ['eslint:recommended'],
      env: {
        es2022: true
      },
      parserOptions: {
        sourceType: 'module'
      }
    },
    {
      files: ['schema.*.graphql'],
      extends: ['plugin:@graphql-eslint/schema-recommended'],
      rules: {
        '@graphql-eslint/require-description': 'off'
      }
    },
    {
      files: ['*.js/*.graphql'],
      extends: ['plugin:@graphql-eslint/operations-recommended']
    }
  ]
}