Skip to content

Menu

GraphQL Query Builder

Build GraphQL queries with variables

Runs entirely in your browserAPI & HTTPFree, no sign-up
Loading tool

01What is GraphQL Query Builder?

Hand-writing GraphQL gets fiddly once you have nested selections and a handful of variables. Forget one declaration in the operation header and the server rejects the whole request. This builder takes a different route. You describe the operation as a small JSON object and it prints a neatly indented GraphQL document from it. The config has an optional type (query, mutation or subscription, with query as the default), an optional operationName, a fields array and a variables object. Each field has a name, optional args and optional children, and you can nest children as deep as you need. The part that saves real effort is variable handling. Any argument whose value starts with $ is collected, together with the type you give it, into the operation signature. Each variable is declared once, even if you use it in five places. If you forget a type, or give the same variable two different types, you get a clear error instead of a document the server would refuse. The rules come from the GraphQL specification. Names for fields, arguments, variables and operations must start with a letter or underscore and contain only letters, digits and underscores. Aliases written as "small: image" are accepted. An empty fields list is refused, because the spec does not allow an empty selection set. Here is a quick example. A mutation named CreatePost with one field, createPost, taking an input argument of "$input" typed CreatePostInput!, and children id and title, comes out as mutation CreatePost($input: CreatePostInput!) followed by createPost(input: $input) with id and title indented inside. The variables object is pretty-printed in its own panel, ready for the JSON body of your HTTP request. Literal values are copied into the document exactly as you typed them. That is handy for numbers like 10, but it also means a string literal needs its own escaped quotes. Otherwise you get a bare word, which GraphQL reads as an enum value. Be clear about the limits. The tool has no idea what your schema looks like, so it cannot tell you whether a field, argument or type exists. It checks that the document is well formed, nothing more. Run it against your server or a schema-aware editor to catch typos in field names. Malformed JSON shows the parser error under the editor and leaves the output empty. The query is built on your machine; no request goes to any GraphQL server.

Front-end and API developers who write GraphQL operations by hand or from templates and want the variable declarations right the first time. The tool runs entirely in your browser, so your data never leaves your device.

02How to use GraphQL Query Builder

  1. Load one of the examples to see the expected config shape.
  2. Edit Query Config (JSON): set type, operationName, the fields tree and variables.
  3. Give each $variable argument a GraphQL type such as ID!, Int or CreatePostInput!.
  4. Read the Generated Query and Variables panels, and check for an error message below the editor.
  5. Click Copy Query to copy the operation with its variables, or Reset to clear the editor.

03Worked examples

Input: {"operationName":"GetUser","fields":[{"name":"user","args":[{"name":"id","value":"$id","type":"ID!"}],"children":[{"name":"name"},{"name":"avatar: avatarUrl"}]}]}
Result: query GetUser($id: ID!) { user(id: $id) { name avatar: avatarUrl } }
Arguments whose value starts with $ are collected into the variable declarations. "avatar: avatarUrl" is an alias.
Input: {"type":"mutation","operationName":"CreatePost","fields":[{"name":"createPost","args":[{"name":"input","value":"$input","type":"CreatePostInput!"}],"children":[{"name":"id"},{"name":"title"}]}]}
Result: mutation CreatePost($input: CreatePostInput!) { createPost(input: $input) { id title } }
A typical mutation with a single input object variable.
Input: Repo query: repository(owner: $owner String!, name: $name String!) > issues(first: 5) > edges > node > title, plus pageInfo { hasNextPage endCursor }
Result: query Repo($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { issues(first: 5) { edges { node { title } } pageInfo { hasNextPage endCursor } } } }
Input summarised in prose; the full JSON nests children four levels deep. Literal 5 is printed inline.
Input: {"type":"subscription","fields":[{"name":"messageAdded","args":[{"name":"room","value":"$room","type":"ID!"}],"children":[{"name":"text"}]}]}
Result: subscription ($room: ID!) { messageAdded(room: $room) { text } }
With no operationName the operation stays anonymous but still declares its variables.
Input: {"fields":[{"name":"user","args":[{"name":"id","value":"$id"}],"children":[{"name":"name"}]}]}
Result: Error: Variable $id needs a "type", e.g. "ID!" or "[String!]".
A variable without a type is refused rather than printed into an invalid document.
Input: {"fields":[{"name":"user-name"}]}
Result: Error: Invalid field name "user-name". Use letters, digits and _ (optionally "alias: field").
Hyphens are not allowed in GraphQL names.

04Common use cases

  • Generating GraphQL operations from a script or template, then checking the printed document before committing it to a .graphql file
  • Writing a Relay-style paginated query with edges, node and pageInfo for the GitHub GraphQL API
  • Preparing a mutation and a matching variables object for a Postman or Insomnia collection
  • Showing a junior developer how variable declarations in the header map to arguments in the body of an Apollo Client query
  • Catching a variable used with two different types across nested fields before the server rejects it
  • Drafting a subscription document for a chat or notifications feature while the schema is still being designed

05Tips

  • String literals need their own quotes inside the value, for example "value": "\"admin\"". Without them the word is printed bare and GraphQL treats it as an enum.
  • Name your operations. Servers and APM tools group traces and logs by operation name, and anonymous queries all land in one bucket.
  • Prefer variables over inline literals so persisted queries and server caches can reuse the same document.
  • The copied output ends with a # Variables comment and the JSON variables. Keep only the operation when saving a .graphql file.
  • Aliases let you fetch the same field twice with different arguments, such as "small: avatar" and "large: avatar".

06Related concepts

GraphQL operations, Query variables, Selection sets, Mutations, Cursor pagination.

Frequently Asked Questions

What is GraphQL Query Builder?

GraphQL Query Builder is a free, browser-based developer tool on AIDToolStack. Build GraphQL queries with variables It requires no installation or sign-up and works entirely in your browser.

Is GraphQL Query Builder free to use?

Yes. No sign-up, no fees and no usage cap.

Does GraphQL Query Builder store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe