{"id":19775,"library":"eslint-plugin-graphql","title":"ESLint Plugin GraphQL","description":"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.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/apollostack/eslint-plugin-graphql","tags":["javascript"],"install":[{"cmd":"npm install eslint-plugin-graphql","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-graphql","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-graphql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for GraphQL schema parsing and validation","package":"graphql","optional":false}],"imports":[{"note":"This is a CommonJS ESLint plugin; import it via ESLint config file, not in application code.","wrong":"// Do not use:\nimport graphqlPlugin from 'eslint-plugin-graphql';\n// Plugin is loaded via ESLint config, not directly imported.","symbol":"default","correct":"module.exports = {\n  plugins: ['graphql'],\n  rules: {\n    'graphql/template-strings': ['error', { env: 'apollo', schemaJson: {} }]\n  }\n}"},{"note":"Use fake-tag (or a real GraphQL client tag like gql from graphql-tag) to provide an identity tag for untagged queries.","wrong":"// Do not use an untagged template string:\nconst query = `{ __typename }`;\n// The plugin only recognizes tagged strings.","symbol":"fake-tag","correct":"import gql from 'fake-tag';\nconst query = gql`{ __typename }`"},{"note":"The plugin registers a single rule 'template-strings'. Use it with an array of options including env and schema definition.","wrong":"// Misspelling or wrong rule name:\n'graphql/templateString': 'error'\n// The correct rule name is 'template-strings'.","symbol":"template-strings","correct":"rules: {\n  'graphql/template-strings': ['error', {\n    env: 'apollo',\n    schemaJson: require('./schema.json')\n  }]\n}"}],"quickstart":{"code":"// eslint.config.js (ESLint >=9 flat config)\nimport graphqlPlugin from 'eslint-plugin-graphql';\nimport { readFileSync } from 'fs';\n\nexport default [\n  {\n    plugins: {\n      graphql: graphqlPlugin\n    },\n    rules: {\n      'graphql/template-strings': ['error', {\n        env: 'apollo',\n        schemaJson: JSON.parse(readFileSync('./schema.json', 'utf8'))\n      }]\n    }\n  }\n];\n\n// In a .js file:\nimport gql from 'graphql-tag';\nconst query = gql`\n  query GetUser($id: ID!) {\n    user(id: $id) {\n      name\n      email\n    }\n  }\n`;","lang":"javascript","description":"Flat ESLint config setup with Apollo client env, loading schema from JSON, and a sample tagged GraphQL query."},"warnings":[{"fix":"Use a tag (e.g., gql from graphql-tag or fake-tag) before your query string.","message":"The plugin only lints tagged template literals; untagged strings are ignored.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"For ESLint <9, use .eslintrc with plugins: ['graphql']. For ESLint >=9, use flat config as shown in quickstart.","message":"ESLint <9 requires plugins to be added via 'plugins' array; flat config (>=9) is supported by this package but may require additional setup.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Use schemaJson or schemaString instead of schemaJsonFilepath if caching is needed.","message":"schemaJsonFilepath option is incompatible with eslint --cache.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure Node >=10 and graphql ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0.","message":"v4.0.0 dropped support for Node <10 and older graphql versions.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Set projectName option if your .graphqlconfig defines multiple projects.","message":"Importing schema from a remote source using .graphqlconfig may not work if project name is missing.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install graphql@^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 --save-dev","cause":"Missing peer dependency graphql.","error":"Error: Cannot find module 'graphql'"},{"fix":"Add plugins: ['graphql'] to your ESLint config (or equivalent for flat config).","cause":"Plugin not registered in ESLint config.","error":"Definition for rule 'graphql/template-strings' was not found"},{"fix":"Use schemaJson, schemaJsonFilepath, or schemaString.","cause":"Using unknown option name 'schema' instead of correct one.","error":"Invalid option 'schema' - must be one of schemaJson, schemaJsonFilepath, schemaString"},{"fix":"Ensure .graphqlconfig is correctly formatted and includes a default or specified project.","cause":"Missing or malformed .graphqlconfig file or missing projectName.","error":"Cannot read property 'schema' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}