0
0
Postmantesting~5 mins

GraphQL body in Postman

Choose your learning style9 modes available
Introduction

GraphQL body lets you send queries or mutations to a GraphQL server in a structured way. It helps you ask for exactly the data you want.

When you want to test a GraphQL API endpoint in Postman.
When you need to send a query to get specific data from a server.
When you want to send a mutation to change data on the server.
When you want to test how the server responds to different GraphQL requests.
When you want to check error handling for invalid GraphQL queries.
Syntax
Postman
{
  "query": "GraphQL query or mutation string",
  "variables": { /* optional variables object */ }
}

The query field contains the GraphQL query or mutation as a string.

The variables field is optional and holds any variables your query uses.

Examples
A simple query asking for a user's name and email by ID.
Postman
{
  "query": "{ user(id: \"1\") { name email } }"
}
A mutation to add a new user named Alice and get back her id and name.
Postman
{
  "query": "mutation { addUser(name: \"Alice\") { id name } }"
}
A query using variables to get user data for id 2.
Postman
{
  "query": "query getUser($id: ID!) { user(id: $id) { name email } }",
  "variables": { "id": "2" }
}
Sample Program

This GraphQL body queries a book by its ID 101, asking for its title and author.

Postman
{
  "query": "query getBook($bookId: ID!) { book(id: $bookId) { title author } }",
  "variables": { "bookId": "101" }
}
OutputSuccess
Important Notes

Always use double quotes for JSON keys and string values in the GraphQL body.

Variables help keep queries clean and reusable.

GraphQL body must be sent as raw JSON with Content-Type set to application/json in Postman.

Summary

GraphQL body is a JSON object with a query string and optional variables.

It lets you send precise queries or mutations to a GraphQL API.

Use variables to make queries flexible and easier to test.