GraphQL Query Builder

Outline your fields, declare variables and get a prettified GraphQL document plus a ready-to-POST JSON body.

Operation type
Variables

Syntax per line: field, alias: field, field(arg: $var, limit: 5), ... on Type. Lines starting with # are ignored. Tab inserts 2 spaces.

Generated query
query GetUser($id: ID!, $first: Int = 10) {
  user(id: $id) {
    id
    name
    avatar: profilePicture(size: 64)
    posts(first: $first) {
      edges {
        node {
          id
          title
        }
      }
    }
  }
}
JSON request body (POST)
{
  "operationName": "GetUser",
  "query": "query GetUser($id: ID!, $first: Int = 10) {\n  user(id: $id) {\n    id\n    name\n    avatar: profilePicture(size: 64)\n    posts(first: $first) {\n      edges {\n        node {\n          id\n          title\n        }\n      }\n    }\n  }\n}",
  "variables": {
    "id": "42"
  }
}

What this builder is for

Hand-writing GraphQL is easy until the selection gets three or four levels deep: a missing closing brace, a variable declared as $userId but used as $id, or a forgotten ! on a type is enough for the server to reject the whole request. This tool lets you describe the operation as a simple indented outline — the way you think about the data — and generates a correctly nested, consistently indented document from it.

It is useful when you are exploring a new API from its documentation, writing a quick request for curl or a test, preparing an example for a README, or teaching someone how selection sets, arguments and variables fit together. Alongside the query it produces the JSON body that GraphQL servers expect over HTTP, so you can paste it straight into a POST request.

How to use it

  1. Choose the Operation type (query, mutation or subscription) and, optionally, an Operation name such as GetUser.
  2. Under Variables, press + Add variable for each input: a name (without $), a type and an optional default.
  3. In Fields, write one field per line. Indent child fields by two spaces (the Tab key inserts them). Add arguments in parentheses and reference variables with $name.
  4. Press Fill from variables to create a skeleton in Variables JSON, then type real values.
  5. Fix anything listed in the red box, then use Copy query, Download .graphql or Copy body.

Worked example

Press Query example. It declares id: ID! and first: Int = 10 and uses this outline:

user(id: $id)
  id
  name
  avatar: profilePicture(size: 64)
  posts(first: $first)
    edges
      node
        id
        title

The builder generates:

query GetUser($id: ID!, $first: Int = 10) {
  user(id: $id) {
    id
    name
    avatar: profilePicture(size: 64)
    posts(first: $first) {
      edges {
        node {
          id
          title
        }
      }
    }
  }
}

and a request body of the form { "operationName": "GetUser", "query": "…", "variables": { "id": "42" } }. The avatar: prefix is an alias: the response will contain the profile picture URL under the key avatar instead of profilePicture.

What each line can contain

  • field — a plain field. If indented lines follow, it becomes an object with a selection set.
  • alias: field — rename the field in the response, needed when you query the same field twice with different arguments.
  • field(arg: value, other: $var) — arguments are copied exactly as written, so use GraphQL literals: strings in double quotes, enums bare (orderBy: CREATED_AT), objects in braces.
  • ... on Type — an inline fragment for unions and interfaces; it must have indented fields below it. Add __typename to know which type came back.
  • Lines starting with # and empty lines are ignored.

Variable types follow GraphQL notation: ! means non-null and square brackets mean a list, so [ID!]! is a required list of required IDs. The GraphQL specification requires every declared variable to be used and every used variable to be declared; the builder flags both mistakes before your server does.

Limitations

  • There is no schema introspection, so field names, argument names and types are not checked against your API.
  • Named fragments and directives such as @include are not supported in the outline; add them to the copied query by hand if you need them.
  • The tool does not execute requests. Use your GraphQL client, or send the copied body with curl — the cURL to code converter can turn that command into fetch, Python or Go.

Tips

  • Prefer variables over inline values: the query text stays constant, which helps server-side caching and persisted queries, and you avoid escaping user input into the query string.
  • Ask only for the fields you render. Over-selecting in GraphQL costs the same as over-fetching in REST.
  • For mutations, select the returned object's id so client caches such as Apollo can update automatically.
  • Inspecting a large response? Paste it into the JSON viewer to browse it as a tree.

Frequently Asked Questions

How do I nest fields in the GraphQL query builder?

Write one field per line and indent child fields by two spaces under their parent. The builder turns every indented block into a { } selection set, at any depth.

Does it support GraphQL variables?

Yes. Declare each variable with a name, a type such as ID! or [String!] and an optional default value, reference it as $name in the arguments, and fill the Variables JSON panel. The tool reports variables that are used but not declared, or declared but never used.

Can I send the query to my GraphQL API from here?

No. The builder only generates text; it never contacts your endpoint. Copy the query into your client (Apollo, urql, Insomnia, Postman) or copy the JSON request body and POST it with curl or fetch.

Does the builder know my schema?

No. It does not run introspection, so it cannot tell whether a field exists or needs a sub-selection. It checks GraphQL syntax rules — names, brackets, indentation and variables — and your server validates the rest.

What is the difference between a query, a mutation and a subscription?

A query reads data, a mutation changes data and returns the result, and a subscription keeps a connection open (usually a WebSocket) to receive events. The document syntax is the same; only the operation keyword changes.

Is anything I type sent to a server?

No. The query, variables and JSON body are built in your browser with plain JavaScript and are never uploaded.