What is the purpose of the GraphQL body in a Postman request?
The GraphQL body contains the query or mutation that specifies exactly what data you want to fetch or change from the GraphQL server.
Click to reveal answer
beginner
How do you format a GraphQL body in Postman?
You format it as a JSON object with a "query" field containing your GraphQL query string, and optionally a "variables" field for dynamic values.
Click to reveal answer
beginner
Example of a simple GraphQL query body in Postman?
{
"query": "{ user(id: \"1\") { name email } }"
} This fetches the name and email of the user with id 1.
Click to reveal answer
intermediate
Why use variables in a GraphQL body?
Variables let you reuse queries with different inputs without changing the query string, making tests cleaner and easier to maintain.
Click to reveal answer
beginner
What content type should you set in Postman when sending a GraphQL body?
Set the Content-Type header to "application/json" because the GraphQL body is sent as a JSON object.
Click to reveal answer
What key must be included in the JSON body to send a GraphQL query in Postman?
A"query"
B"request"
C"body"
D"data"
✗ Incorrect
The GraphQL query must be inside the "query" key in the JSON body.
How do you include variables in a GraphQL request body?
AIn the HTTP headers
BInside the "query" string directly
CInside the "variables" key as a JSON object
DIn the URL parameters
✗ Incorrect
Variables are passed as a JSON object inside the "variables" key in the request body.
Which HTTP method is typically used to send a GraphQL body in Postman?
APOST
BGET
CPUT
DDELETE
✗ Incorrect
GraphQL queries and mutations are usually sent using POST requests.
What Content-Type header should you set for a GraphQL request in Postman?
Atext/plain
Bapplication/json
Capplication/graphql
Dmultipart/form-data
✗ Incorrect
GraphQL requests in Postman are sent as JSON, so Content-Type should be application/json.
Why is it better to use variables in GraphQL queries?
ATo send queries faster
BTo make the query longer
CTo bypass authentication
DTo avoid repeating the same query with different values
✗ Incorrect
Variables let you reuse the same query with different inputs, making tests simpler and cleaner.
Explain how to structure a GraphQL body in Postman for a query with variables.
Think about how to separate the query and the dynamic data.
You got /3 concepts.
Describe the steps to test a GraphQL API using Postman.
Consider what you need to prepare before sending the request.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of the query field in a GraphQL body when testing with Postman?
easy
A. To list all available API endpoints
B. To define the HTTP headers for the request
C. To set the URL of the GraphQL endpoint
D. To specify the exact data you want to fetch or mutate from the API
Solution
Step 1: Understand the role of the query field
The query field contains the GraphQL query or mutation string that tells the API exactly what data to return or change.
Step 2: Differentiate from other request parts
Headers and URLs are set elsewhere in Postman; the query field is specifically for the GraphQL operation.
Final Answer:
To specify the exact data you want to fetch or mutate from the API -> Option D
Quick Check:
GraphQL query = data request [OK]
Hint: Remember: query means what data you want [OK]
Common Mistakes:
Confusing query with HTTP headers
Trying to put URL or endpoint inside query
Leaving query empty or missing
2. Which of the following is the correct minimal structure of a GraphQL body in Postman?
easy
A. { "query": "{ user { id name } }" }
B. { "url": "https://api.example.com/graphql" }
C. { "headers": { "Content-Type": "application/json" } }
D. { "variables": { "id": 1 } }
Solution
Step 1: Identify the required fields in a GraphQL body
The minimal GraphQL body must have a query field with a valid query string.
Step 2: Check each option
{ "query": "{ user { id name } }" } correctly shows a JSON object with a query string. The structures with "url" and "headers" are for other parts of the Postman request, not the body. { "variables": { "id": 1 } } only has variables without a query, which is invalid.
Final Answer:
{ "query": "{ user { id name } }" } -> Option A
Quick Check:
GraphQL body needs query string [OK]
Hint: GraphQL body always needs a query string [OK]
The API returns an error about missing variables. What is the fix?
medium
A. Add a variables field with the required id value
B. Remove the $id variable from the query
C. Change the query to a mutation
D. Add HTTP headers for authentication
Solution
Step 1: Identify the cause of the error
The query requires a variable $id but no variables field was sent, so the API complains about missing input.
Step 2: Fix by adding variables
Include a variables JSON object with the id value, e.g., { "id": "123" }, to satisfy the query requirement.
Final Answer:
Add a variables field with the required id value -> Option A
Quick Check:
Variables must match query parameters [OK]
Hint: Always send variables if query requires them [OK]
Common Mistakes:
Forgetting to send variables when query uses them
Trying to remove variables from query without adjusting logic
Assuming authentication fixes variable errors
5. You want to test a GraphQL mutation to update a user's email using variables in Postman. Which GraphQL body correctly uses variables for this mutation?