GraphQL Schema Validator

1

Paste Schema

Enter your GraphQL schema definition (SDL)

2

Validate

Click Validate to check for syntax errors

3

Format

Get formatted schema with proper indentation

Input Schema (SDL)

Formatted Schema

Features

Validate GraphQL SDL syntax
Format and beautify schemas
Error detection with line numbers
Type definition validation
Field and argument checking
Directive validation
Copy formatted schema
Download as .graphql file
100% client-side processing
Works offline after loading

What is GraphQL Schema Validation?

GraphQL schema validation ensures that your GraphQL Schema Definition Language (SDL) is syntactically correct and follows GraphQL specifications. A valid schema is essential for your GraphQL API to function properly, as it defines the types, queries, mutations, and relationships in your API.

Our validator checks for common errors like missing type definitions, invalid field types, incorrect syntax, and schema inconsistencies. It helps catch errors early in development before they cause runtime issues in your GraphQL server.

Why Validate GraphQL Schemas?

Valid GraphQL Schema Example:
type User {
  id: ID!
  name: String!
  email: String!
  posts: [Post!]!
}

type Query {
  user(id: ID!): User
  users: [User!]!
}

How to Use the GraphQL Validator

Step 1: Paste Your Schema

Copy your GraphQL schema definition from your project and paste it into the input area. The schema should be in SDL (Schema Definition Language) format, which is the standard way to define GraphQL schemas.

Step 2: Validate the Schema

Click "Validate Schema" to check for syntax errors and schema issues. The validator will report any problems with specific line numbers and descriptions, making it easy to locate and fix errors.

Step 3: Format and Use

Once validated, click "Format Schema" to get a properly formatted version with consistent indentation and spacing. Copy the formatted schema back to your project or download it as a .graphql file.

Understanding Validation Errors

Common validation errors include undefined types, missing required fields, invalid field types, and syntax errors. The validator provides detailed error messages to help you quickly identify and fix issues.

Common Use Cases

1. API Development

Validate your GraphQL schema during API development to ensure it's correctly structured before implementing resolvers. This prevents runtime errors and ensures your API contract is solid.

2. Schema Refactoring

When refactoring your GraphQL schema, use the validator to ensure changes don't introduce errors. Validate after each change to catch issues immediately rather than discovering them during testing.

3. Code Review

Validate schemas during code review to ensure proposed changes maintain schema integrity. Well-formatted, validated schemas make reviews faster and more effective.

4. Documentation Generation

Many GraphQL documentation tools require valid schemas. Validate and format your schema before generating documentation to ensure accurate, complete API docs.

5. Client Code Generation

Tools like GraphQL Code Generator require valid schemas to generate TypeScript types or other client code. Validate your schema first to ensure successful code generation.

GraphQL Schema Examples

Example 1: Basic Types

type User {
  id: ID!
  name: String!
  email: String!
  age: Int
  isActive: Boolean!
}

type Query {
  user(id: ID!): User
  users: [User!]!
}

Example 2: Relationships

type Author {
  id: ID!
  name: String!
  books: [Book!]!
}

type Book {
  id: ID!
  title: String!
  author: Author!
  publishedYear: Int!
}

Example 3: Input Types

input CreateUserInput {
  name: String!
  email: String!
  age: Int
}

type Mutation {
  createUser(input: CreateUserInput!): User!
  updateUser(id: ID!, input: CreateUserInput!): User!
}

Example 4: Enums and Interfaces

enum Role {
  ADMIN
  USER
  GUEST
}

interface Node {
  id: ID!
}

type User implements Node {
  id: ID!
  name: String!
  role: Role!
}

Example 5: Directives

type User {
  id: ID!
  name: String!
  email: String! @deprecated(reason: "Use emailAddress instead")
  emailAddress: String!
  password: String! @auth(requires: ADMIN)
}

Frequently Asked Questions

What is GraphQL SDL?
SDL (Schema Definition Language) is the syntax used to define GraphQL schemas. It's a human-readable way to describe types, queries, mutations, and their relationships in a GraphQL API.
What does the exclamation mark (!) mean?
The exclamation mark indicates a non-nullable field. For example, String! means the field must return a string and cannot be null. Without !, the field can return null.
What's the difference between [User] and [User!]?
[User] means an array that can contain null values. [User!] means an array where each element must be a User (no nulls in the array). [User]! means the array itself cannot be null but can contain nulls.
Can I validate schema fragments?
This validator is designed for complete schemas. For fragments, you need the full schema context. However, you can paste your fragment into a complete schema to validate it.
What are Input types used for?
Input types are used for mutation arguments. They're similar to regular types but can only contain scalar fields and other input types. They cannot have fields that return object types.
How do I define custom scalars?
Define custom scalars with: scalar DateTime. The validator will accept the definition, but you'll need to implement the scalar's serialization logic in your GraphQL server.
What are directives in GraphQL?
Directives like @deprecated or @auth add metadata to schema elements. They're prefixed with @ and can take arguments. Common directives include @deprecated, @include, and @skip.
Can I use this for schema stitching?
Yes, validate each schema separately before stitching. Schema stitching combines multiple schemas, so each individual schema should be valid before merging.
Is my schema data sent to a server?
No, all validation happens in your browser using JavaScript. Your schema never leaves your computer, making this tool safe for proprietary or sensitive API schemas.
Does this work offline?
Yes, once the page is loaded, all validation and formatting happens in your browser. You can use the tool completely offline without an internet connection.

Related Tools

Explore our other API and data tools:

💙

Support TechConverter

Get $200 free DigitalOcean credit or sponsor us on GitHub!