An ESLint plugin that validates GraphQL query strings in JavaScript tagged template literals and .graphql files against a GraphQL schema. Version 4.0.0 supports Node >=10.0 and peer dependency graphql ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0. Maintained under the Apollo GraphQL ecosystem. Provides built-in client profiles for Apollo, Relay, Lokka, and FraQL. Unlike graphql-schema-linter (which validates schema definitions), this plugin focuses on linting query usage in application code. Release cadence is irregular; latest release (4.0.0) was published in 2020.
npm install eslint-plugin-graphqlVerified import paths — ran on the pinned version, not inferred.
Flat ESLint config setup with Apollo client env, loading schema from JSON, and a sample tagged GraphQL query.
Use a tag (e.g., gql from graphql-tag or fake-tag) before your query string.
For ESLint <9, use .eslintrc with plugins: ['graphql']. For ESLint >=9, use flat config as shown in quickstart.
Use schemaJson or schemaString instead of schemaJsonFilepath if caching is needed.
Ensure Node >=10 and graphql ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0.
Set projectName option if your .graphqlconfig defines multiple projects.
npm install graphql@^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 --save-dev
Add plugins: ['graphql'] to your ESLint config (or equivalent for flat config).
Use schemaJson, schemaJsonFilepath, or schemaString.
Ensure .graphqlconfig is correctly formatted and includes a default or specified project.