GraphQL API testing in Postman allows you to validate queries and mutations by sending structured requests to a single endpoint. Unlike REST, GraphQL uses a flexible query language where clients request exactly the data they need.
In Postman, GraphQL requests are usually sent as HTTP POST requests with a JSON body. The body contains a query field and optional variables.
// Basic GraphQL request structure
{
"query": "query { users { id name email } }"
}
// Fetching user list using GraphQL query
query {
users {
id
name
email
}
}
// Creating a new user using GraphQL mutation
mutation {
createUser(name: "Rahul", email: "rahul@test.com") {
id
name
email
}
}
The server responds with a JSON object containing a data field. Only the requested fields appear in the response, making GraphQL efficient and predictable.
Try switching between query and mutation tabs inside Postman’s GraphQL editor. You can also use Postman’s built-in schema explorer to auto-generate queries.
// Example of GraphQL variables in Postman
{
"query": "query GetUser($id: ID!) { user(id: $id) { name email } }",
"variables": { "id": "1" }
}