GraphQL Schema Formatter and Linter
Format and validate GraphQL SDL schema files — with type checking and linting.
Published:
Tags: GraphQL schema formatter, GraphQL SDL formatter, GraphQL schema validator
GraphQL Schema Formatter and Linter The GraphQL specification defines the Schema Definition Language (SDL) and all type system features. The reference implementation graphql-js on GitHub provides the and functions used by formatters. GraphQL adoption has grown 40% year-over-year and is now used by 40%+ of companies with 1000+ employees for API development, according to State of GraphQL 2024 GraphQL SDL (Schema Definition Language) defines your API's type system. A formatter normalizes whitespace and structure; a linter enforces naming conventions and completeness. Both run before code generation and documentation to prevent schema drift. --- What are the basics of GraphQL SDL? A GraphQL schema defines types and the operations that query them: Formatting GraphQL SDL? The graphql-js library…
Frequently Asked Questions
How do I format a GraphQL schema?
A GraphQL formatter parses the SDL using the graphql-js library's `parse()` function and re-serializes with `print()`. This normalizes whitespace, field ordering within each type, and removes redundant formatting.
What is GraphQL SDL?
SDL (Schema Definition Language) is the human-readable syntax for defining GraphQL schemas. It defines types, queries, mutations, subscriptions, enums, interfaces, unions, and input types. SDL files typically have a `.graphql` or `.gql` extension.
How do I lint a GraphQL schema?
Use graphql-eslint or graphql-inspector to apply naming conventions, require descriptions on public types and fields, detect breaking changes, and check for deprecated field usage. Install with `npm install -D @graphql-eslint/eslint-plugin`.
How do I validate GraphQL types?
The graphql-js library's `buildSchema()` and `validate()` functions check that type references resolve, interface implementations are complete, and field return types are defined. Invalid schemas throw detailed error messages with line numbers.
What is the graphql-eslint tool?
graphql-eslint is an ESLint plugin that applies lint rules to GraphQL SDL files and GraphQL operations within JavaScript/TypeScript files. Rules enforce naming conventions, require descriptions, validate known type usage, and detect N+1 patterns.
All articles · theproductguy.in