Registry / testing / graphql-schema-linter

graphql-schema-linter

JSON →
library3.0.1jsnpmunverified

Command-line tool and library for validating GraphQL schema definitions against a configurable set of rules. Current stable version is 3.0.1, with monthly releases. It supports custom rules, multiple output formats (compact, JSON, text), and integration with pre-commit hooks via lint-staged. Unlike graphql-eslint or other query-focused tools, this linter targets schema definition files (.graphql) and enforces best practices like field descriptions, type naming conventions, and alphabetical sorting. Requires graphql as a peer dependency (v15 or v16).

npm install graphql-schema-linter
INSTALL
IMPORT
SIG · GRAPHQL-SCHEMA-LIN
G
graphql-schema-linter
testingjavascriptv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import lint from 'graphql-schema-linter'
const { lint } = require('graphql-schema-linter')
The package exports a default function. Named exports like 'lint' are incorrect.
LintResult
import type { LintResult } from 'graphql-schema-linter'
const LintResult = require('graphql-schema-linter').LintResult
LintResult is a TypeScript type, not a runtime value. Use type import.
getRules
import { getRules } from 'graphql-schema-linter'
const getRules = require('graphql-schema-linter').getRules
getRules is a named export, available as ESM export since v3.

Lints a GraphQL schema file with specific rules and outputs the result as text.

import fs from 'fs'; import lint from 'graphql-schema-linter'; import { getRules } from 'graphql-schema-linter'; const schemaSDL = fs.readFileSync('./schema.graphql', 'utf8'); const rules = getRules(); // or pick specific rules lint(schemaSDL, { rules: ['fields-have-descriptions', 'types-have-descriptions'], format: 'text' }).then((result) => { console.log(result); }).catch((err) => { console.error(err); });
Debug
Known issues
breakingv3 migrated to ESM-only; CommonJS require() no longer works.
fix
Use ES module imports or upgrade to Node.js 14+ and set 'type': 'module' in package.json.
affects: >=3.0.0
breakingDefault export changed: v2 used named exports, v3 exports a default function.
fix
Change 'import { lint } from 'graphql-schema-linter'' to 'import lint from 'graphql-schema-linter''.
affects: >=3.0.0
deprecatedThe --comment-descriptions and --old-implements-syntax flags are deprecated and will be removed in v4.
fix
Update to GraphQL spec compliant syntax; these flags are only for legacy schemas.
affects: >=3.0.0
gotchaWhen using lint-staged, multiple .graphql files in the same folder are treated as parts of one schema unless separately configured.
fix
Explicitly list schema files or use separate patterns in lint-staged config.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql'
GraphQL peer dependency not installed.
fix
Run 'npm install graphql' or 'yarn add graphql'.
TypeError: lint is not a function
Incorrect import due to v3 breaking change (default vs named export).
fix
Use 'import lint from 'graphql-schema-linter'' instead of 'import { lint } ...'.
Error: Rules must be an array of strings or rule objects
Invalid rules option passed to lint function.
fix
Ensure the 'rules' option is an array, e.g., ['fields-have-descriptions'].
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency; the linter validates GraphQL schemas using the graphql-js library.
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-schema-linter — npm install graphql-schema-linter · libregistry