Select Fields
Sample Schema
type User {
id: ID!
name: String!
email: String!
age: Int
createdAt: String!
posts: [Post!]!
friends: [User!]!
}
type Post {
id: ID!
title: String!
content: String
author: User!
comments: [Comment!]!
createdAt: String!
}
type Comment {
id: ID!
text: String!
author: User!
post: Post!
createdAt: String!
}
type Query {
user(id: ID!): User
users(limit: Int, offset: Int): [User!]!
post(id: ID!): Post
posts(limit: Int): [Post!]!
searchUsers(query: String!): [User!]!
}
type Mutation {
createUser(name: String!, email: String!, age: Int): User!
updateUser(id: ID!, name: String, email: String): User
deleteUser(id: ID!): Boolean
createPost(title: String!, content: String): Post!
addComment(postId: ID!, text: String!): Comment!
}
Use this tool to quickly build GraphQL queries. Select your operation type, choose fields, and generate the query string. For more complex queries, you can add nested field selections.
What is GraphQL Query Builder?
GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need in a single request, eliminating the over-fetching and under-fetching problems common with REST endpoints. Instead of multiple round trips to different endpoints, a GraphQL client sends one query that specifies the exact shape of the response. The server returns a JSON object matching that shape, making GraphQL especially powerful for mobile applications and complex data graphs where network efficiency matters. Operations come in three types: queries for reading data, mutations for writing data, and subscriptions for receiving real-time updates over WebSocket connections.
How to Use
- Select an operation type — Query for fetching data, Mutation for modifying data, or Subscription for live updates
- Choose the operation name from the dropdown to target a specific field in your GraphQL schema
- Toggle the fields you want the server to return; nested fields like posts expand to reveal sub-selections you can also toggle
- Optionally add variables (e.g., $id: ID!) for parameterized queries and an alias to name your operation for better debugging
- Click Generate Query to produce properly formatted GraphQL syntax, then copy it into your application code or GraphiQL explorer
Why Use This Tool?
Tips & Best Practices
- Use aliases when you need to query the same field multiple times with different arguments in a single request
- Always include the id field in your selections — client-side caching libraries like Apollo and Relay rely on it for normalization
- Extract repeated field selections into GraphQL fragments to keep your queries DRY and maintainable
- For mutations, always request the modified object back so you can verify the server applied the changes correctly
Frequently Asked Questions
What is the difference between Query, Mutation, and Subscription?
Queries read data without side effects, similar to GET in REST. Mutations modify data (create, update, delete) and return the result, similar to POST/PUT/DELETE. Subscriptions establish a persistent WebSocket connection and push real-time updates to the client whenever the underlying data changes. Use queries for dashboards, mutations for forms, and subscriptions for live feeds.
How do variables improve GraphQL queries?
Variables separate dynamic values from the query text, which prevents injection attacks, enables query caching on the server, and makes queries reusable across different contexts. Define variables in the operation signature (query GetUser($id: ID!)) and pass their values as a separate JSON object alongside the query string.
Can I use this builder with any GraphQL API?
This builder uses a built-in sample schema for demonstration. To use it with your own API, you would need to adapt the schema and available operations to match your server's type definitions. The generated query syntax follows the official GraphQL specification and will work with any compliant server once the schema matches.
When should I NOT use GraphQL?
Avoid GraphQL when your API is simple with few endpoints and minimal nesting — REST will be easier to implement and cache. GraphQL also adds complexity for file uploads (which require multipart request handling) and can expose denial-of-service risk through deeply nested queries unless you implement query depth limiting on the server.
Is my query data sent to any server?
No. This tool runs entirely in your browser. The query you build and the sample schema are processed client-side only. Nothing is transmitted to any external server, making it safe to experiment with queries that reference internal or proprietary API schemas.
What are GraphQL fragments and when should I use them?
Fragments are reusable selection sets that you define once and reference in multiple queries. They are especially useful when several queries or mutations need to return the same fields for a given type. For example, fragment UserFields on User { id name email } can be spread into any query that returns a User, reducing duplication and ensuring consistency.
Real-world Examples
Fetching a user with their recent posts
A profile page needs the user's basic info plus their three most recent blog posts, including each post's title and creation date.
query {
user(id: "123") {
id
name
email
posts {
id
title
createdAt
}
}
}{
"user": {
"id": "123",
"name": "Alice Johnson",
"email": "[email protected]",
"posts": [
{ "id": "p1", "title": "GraphQL Basics", "createdAt": "2024-03-15" },
{ "id": "p2", "title": "Advanced Queries", "createdAt": "2024-03-10" }
]
}
}Creating a new user via mutation
A sign-up form submits a mutation to create a user account and immediately receives the new user's ID and email for confirmation.
mutation {
createUser(name: "Bob Lee", email: "[email protected]", age: 30) {
id
name
email
}
}{
"createUser": {
"id": "456",
"name": "Bob Lee",
"email": "[email protected]"
}
}