GraphQL
GraphQL is a query language for APIs that gives clients the power to ask for exactly what they need.
Overview
Making a Query
- Select GraphQL from the protocol dropdown
- Enter the GraphQL endpoint:
https://api.example.com/graphql - Write your query in the editor
- Click Run
Query Editor
The query editor provides:
- Syntax highlighting for GraphQL
- Auto-indentation
- Error highlighting
Basic Query
query {
users {
id
name
email
}
}
Query with Variables
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
posts {
title
}
}
}
Variables (JSON):
{
"id": "123"
}
Mutation
mutation CreateUser($input: CreateUserInput!) {
createUser(input: $input) {
id
name
email
}
}
Variables:
{
"input": {
"name": "John Doe",
"email": "[email protected]"
}
}
Request Configuration
Headers
Add authentication and custom headers:
| Header | Value |
|---|---|
Authorization | Bearer {{TOKEN}} |
X-API-Key | {{API_KEY}} |
Variables
The Variables tab accepts JSON that maps to your query's variables:
{
"id": "user-123",
"limit": 10,
"filter": {
"status": "active"
}
}
Operation Name
When your query contains multiple operations, specify which one to execute:
query GetUsers {
users { id name }
}
query GetPosts {
posts { id title }
}
Set Operation Name to GetUsers or GetPosts.
Response
The response shows:
- data: Query results
- errors: Any GraphQL errors (if present)
- Response time: Request duration
Successful Response
{
"data": {
"users": [
{ "id": "1", "name": "Alice" },
{ "id": "2", "name": "Bob" }
]
}
}
Error Response
{
"data": null,
"errors": [
{
"message": "User not found",
"path": ["user"],
"locations": [{ "line": 2, "column": 3 }]
}
]
}
Playground Example
Using the built-in GraphQL endpoint:
URL: http://localhost:19510/graphql
List Users
query {
users {
id
name
email
createdAt
}
}
Create User
mutation CreateUser($name: String!, $email: String!) {
createUser(name: $name, email: $email) {
id
name
email
}
}
Variables:
{
"name": "New User",
"email": "[email protected]"
}
Get Single User
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
}
}
Variables:
{
"id": "1"
}
Schema Introspection
Fetch the schema SDL from:
GET http://localhost:19510/graphql/sdl
Tips
Use Variables
Always use variables instead of string interpolation for dynamic values. This improves security and caching.
Fragments
Use fragments to reuse field selections:
fragment UserFields on User {
id
name
email
}
query {
users {
...UserFields
}
}