GraphQL Schema Validator - Check GraphQL SDL Online
Check a GraphQL schema definition for syntax errors, unknown types, duplicate names, interface and union mistakes and bad default values, with line and column numbers.
How to Validate GraphQL Schemas - Step by Step Guide
Step 1: Input Your GraphQL Schema
Paste your GraphQL schema definition, upload a .graphql or .gql file, or use the sample data to test the validator.
- •Paste schema directly from your code editor
- •Upload .graphql or .gql files
- •Click "Sample" to load example schema
Example GraphQL Schema
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
content: String!
author: User!
}Step 2: Automatic Schema Validation
About half a second after you stop typing, the schema is built with graphql-js and checked against the rules of the GraphQL specification.
- •Validates GraphQL schema syntax
- •Verifies type definitions and references
- •Reports the line and column of the first problem
- •Checks interface and union types and default values
Step 3: Review Validation Results
View validation results with detailed error messages and schema statistics.
- •Success indicator for valid schemas
- •Error messages with line numbers
- •Schema statistics and type counts
Step 4: Fix and Re-validate
Fix the problem in the editor and the check runs again. Copy and Download give you your schema exactly as typed.
- •Re-checked as you edit
- •Download as schema.graphql
- •Copy to clipboard
Frequently Asked Questions
How do I validate a GraphQL schema?
Paste your type definitions into the editor or upload a .graphql or .gql file. About half a second after you stop typing, the schema is built with graphql-js, the reference GraphQL implementation. You either get a green "Valid Schema" with counts of your types and fields, or the first problem with its line, column and the line itself marked with a caret.
What does the validator actually check?
Everything graphql-js checks when it builds a schema: syntax, types that are used but never defined, duplicate type, field, argument and enum value names, unknown directives, interfaces that a type claims to implement but doesn't fully provide, unions that include non-object types, input types used as output (and the other way round), a missing Query type, and default values that don't fit their type, such as an Int default past 2147483647. It does not run resolvers, lint naming style, or compare against a previous version of your schema.
Why does it say Query root type must be provided?
The GraphQL spec requires every schema to have a query root, so a file that only defines a few types fails on its own. If you are checking one module of a bigger schema, add a placeholder such as type Query { _empty: String } while you check it.
Does it work with Apollo Federation or AWS AppSync schemas?
Only partly. Plain SDL from Apollo Server, GraphQL Yoga and similar servers checks fine. Federation subgraphs use directives like @key and @external, and AppSync adds scalars like AWSDateTime and directives like @aws_auth. Standard GraphQL doesn't know those, so the validator reports them as unknown until you declare them in the file (for example directive @key(fields: String!) repeatable on OBJECT | INTERFACE, or scalar AWSDateTime).
I pasted a query and got an error. Why?
This page checks schema definitions, not operations. A query, mutation or fragment has no type definitions to validate, so the page tells you so instead of guessing. To tidy up a query, use the GraphQL Formatter or GraphQL Minifier.
Is my schema uploaded anywhere?
No. The checking runs in your browser with the graphql-js library, and nothing you paste or upload is sent to our server. Copy and Download give you back exactly the text in the editor.
Working on queries rather than schemas? Try the GraphQL Formatter or the GraphQL Minifier.
Related Tools
GraphQL Query Formatter
Format and beautify GraphQL queries and schemas with syntax highlighting
GraphQL Fixer
Fix broken GraphQL queries and schemas automatically, repair syntax errors and malformed types
GraphQL to TypeScript
Generate TypeScript types from GraphQL schemas and queries
GraphQL Minifier
Compress and optimize GraphQL queries for production
GraphQL to JSON Schema
Convert GraphQL schemas to JSON Schema format
GraphQL to JSON
Convert GraphQL schemas and queries to JSON format