Registry / testing / eslint-plugin-graphql

eslint-plugin-graphql

JSON →
library4.0.0jsnpmunverified

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-graphql
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-GRAP
E
eslint-plugin-graphql
testingjavascriptv4.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ module.exports = { plugins: ['graphql'], rules: { 'graphql/template-strings': ['error', { env: 'apollo', schemaJson: {} }] } }
✗ // Do not use: import graphqlPlugin from 'eslint-plugin-graphql'; // Plugin is loaded via ESLint config, not directly imported.
This is a CommonJS ESLint plugin; import it via ESLint config file, not in application code.
fake-tag
✓ import gql from 'fake-tag'; const query = gql`{ __typename }`
✗ // Do not use an untagged template string: const query = `{ __typename }`; // The plugin only recognizes tagged strings.
Use fake-tag (or a real GraphQL client tag like gql from graphql-tag) to provide an identity tag for untagged queries.
template-strings
✓ rules: { 'graphql/template-strings': ['error', { env: 'apollo', schemaJson: require('./schema.json') }] }
✗ // Misspelling or wrong rule name: 'graphql/templateString': 'error' // The correct rule name is 'template-strings'.
The plugin registers a single rule 'template-strings'. Use it with an array of options including env and schema definition.

Flat ESLint config setup with Apollo client env, loading schema from JSON, and a sample tagged GraphQL query.

// eslint.config.js (ESLint >=9 flat config) import graphqlPlugin from 'eslint-plugin-graphql'; import { readFileSync } from 'fs'; export default [ { plugins: { graphql: graphqlPlugin }, rules: { 'graphql/template-strings': ['error', { env: 'apollo', schemaJson: JSON.parse(readFileSync('./schema.json', 'utf8')) }] } } ]; // In a .js file: import gql from 'graphql-tag'; const query = gql` query GetUser($id: ID!) { user(id: $id) { name email } } `;
Debug
Known issues
gotchaThe plugin only lints tagged template literals; untagged strings are ignored.
fix
Use a tag (e.g., gql from graphql-tag or fake-tag) before your query string.
affects: >=0.0.0
deprecatedESLint <9 requires plugins to be added via 'plugins' array; flat config (>=9) is supported by this package but may require additional setup.
fix
For ESLint <9, use .eslintrc with plugins: ['graphql']. For ESLint >=9, use flat config as shown in quickstart.
affects: >=4.0.0
gotchaschemaJsonFilepath option is incompatible with eslint --cache.
fix
Use schemaJson or schemaString instead of schemaJsonFilepath if caching is needed.
affects: >=3.0.0
breakingv4.0.0 dropped support for Node <10 and older graphql versions.
fix
Ensure Node >=10 and graphql ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0.
affects: >=4.0.0
gotchaImporting schema from a remote source using .graphqlconfig may not work if project name is missing.
fix
Set projectName option if your .graphqlconfig defines multiple projects.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql'
Missing peer dependency graphql.
fix
npm install graphql@^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 --save-dev
Definition for rule 'graphql/template-strings' was not found
Plugin not registered in ESLint config.
fix
Add plugins: ['graphql'] to your ESLint config (or equivalent for flat config).
Invalid option 'schema' - must be one of schemaJson, schemaJsonFilepath, schemaString
Using unknown option name 'schema' instead of correct one.
fix
Use schemaJson, schemaJsonFilepath, or schemaString.
Cannot read property 'schema' of undefined
Missing or malformed .graphqlconfig file or missing projectName.
fix
Ensure .graphqlconfig is correctly formatted and includes a default or specified project.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL schema parsing and validation
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
eslint-plugin-graphql — npm install eslint-plugin-graphql · libregistry