GraphQL to Schema AST screenshot

GraphQL to Schema AST

Parse a GraphQL schema into a schema AST: a Document of type definitions, each with named fields and NamedType, ListType or NonNullType references.

Privacy First
0 Runs
Updated 2026-11-17
Runs in your browser
No sign-up, no upload

What the GraphQL to Schema AST does

A type reference is one of three nodes: NamedType with a Name, ListType wrapping an inner node, or NonNullType wrapping an inner node. That is the whole grammar of a GraphQL type, and the AST prints it literally.

Fields carry their arguments as InputValueDefinition nodes, so an argument's type is readable from the same tree.

The AST is a subset of graphql-js's parse output: names, type references, fields, arguments and directives are present; source locations and descriptions are not.

How to use it

Paste the schema into the GraphQL schema box, or press Run with the example already there.

Read the Schema AST below: definitions holds one node per schema definition, in declaration order.

Check the Schema AST type node — a nullable String is a NamedType, and a non-null one is a NonNullType wrapping it.

Worked example

Input:

type Query {
  ping: String
}

Output:

{
  "kind": "Document",
  "definitions": [
    {
      "kind": "ObjectTypeDefinition",
      "name": {
        "kind": "Name",
        "value": "Query"
      },
      "directives": [],
      "fields": [
        {
          "kind": "FieldDefinition",
          "name": {
            "kind": "Name",
            "value": "ping"
          },
          "arguments": [],
          "type": {
            "kind": "NamedType",
            "name": {
              "kind": "Name",
              "value": "String"
            }
          },
          "directives": []
        }
      ],
      "interfaces": []
    }
  ]
}

Why it runs in your browser

The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.

The schema parsed into the tree a tool walks: a Document holding ObjectTypeDefinition, FieldDefinition and a type node for every field.

Node kinds follow the names graphql-js uses, so a visitor written against that AST reads this document without a translation table.

What it does, and what it does not

A type reference is one of three nodes: NamedType with a Name, ListType wrapping an inner node, or NonNullType wrapping an inner node. That is the whole grammar of a GraphQL type, and the AST prints it literally.

Fields carry their arguments as InputValueDefinition nodes, so an argument's type is readable from the same tree.

The AST is a subset of graphql-js's parse output: names, type references, fields, arguments and directives are present; source locations and descriptions are not.

How to use GraphQL to Schema AST

Paste the schema into the GraphQL schema box, or press Run with the example already there.

Read the Schema AST below: `definitions` holds one node per schema definition, in declaration order.

Check the Schema AST `type` node — a nullable String is a NamedType, and a non-null one is a NonNullType wrapping it.

What to Expect

Best for

  • Feeding a schema into a visitor or codemod
  • Checking how a nested list type is represented

Not ideal for

  • Comparing source locations, which this tree does not carry
  • Reading descriptions, which are not modelled

What this tool keeps

  • Node kinds named as graphql-js names them
  • One node per declared field and argument

What may need cleanup

  • Add source locations if your visitor needs them
  • Descriptions must be read from the schema text, not the AST

Common errors

  • The page refuses it: unknown type Missing referenced by Query.ping

Example use cases

  • Driving a codemod from a schema
  • Teaching how a GraphQL type nests

Sample input

GraphQL schema: type Query { …

Sample output

Schema AST: { …

Who this is for

  • Tool authors working with schemas
  • Anyone debugging a visitor that walks a schema AST

Frequently asked questions

How is a non-null list of strings represented?

As a NonNullType whose inner node is a ListType whose inner node is a NamedType named String. The wrappers nest in that order, outermost first.

Why is there a Document node?

Every GraphQL document is a Document holding definitions. Starting from that node means a visitor needs no special case for a single-type schema.

Are arguments part of the field node?

Yes. Each argument becomes an InputValueDefinition with its own name and type node, in the order the schema declares them.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.