Challenge - 5 Problems
GraphQL Body Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this GraphQL query body in Postman?
Given this GraphQL query body sent in Postman, what will be the value of the "data" field in the response if the server returns the user's name and age correctly?
Postman
{
"query": "query { user(id: \"123\") { name age } }"
}Attempts:
2 left
💡 Hint
The query requests both name and age fields for user with id 123.
✗ Incorrect
The query asks for user with id 123 and requests name and age fields. If the server returns both correctly, the data field will contain both name and age.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the user's email in Postman test script?
You want to check that the user's email returned by this GraphQL query is "user@example.com". Which Postman test script assertion is correct?
Postman
pm.test("User email is correct", function () {
const jsonData = pm.response.json();
// Assertion here
});Attempts:
2 left
💡 Hint
The GraphQL response nests user inside data.
✗ Incorrect
The GraphQL response structure nests the user object inside the data field. The correct path to email is jsonData.data.user.email. The expected email is 'user@example.com'.
❓ locator
advanced2:00remaining
Which JSON path correctly locates the 'posts' array in a GraphQL response body?
Given this GraphQL response body, which JSON path expression correctly locates the 'posts' array inside the 'user' object?
Postman
{
"data": {
"user": {
"id": "123",
"posts": [
{"id": "p1", "title": "Post 1"},
{"id": "p2", "title": "Post 2"}
]
}
}
}Attempts:
2 left
💡 Hint
The 'posts' array is inside 'user', which is inside 'data'.
✗ Incorrect
The JSON path must start from the root '$', then go to 'data', then 'user', then 'posts'. So the correct path is $.data.user.posts.
🔧 Debug
advanced2:00remaining
Why does this GraphQL query body cause a syntax error in Postman?
This GraphQL query body is sent in Postman but causes a syntax error. Identify the cause.
Postman
{
"query": "query { user(id: 123) { name age } }"
}Attempts:
2 left
💡 Hint
GraphQL requires string arguments to be quoted.
✗ Incorrect
In GraphQL, string arguments must be enclosed in double quotes. The id 123 is unquoted, causing a syntax error.
❓ framework
expert3:00remaining
Which Postman test script correctly validates that the 'posts' array has exactly 3 items?
You receive this GraphQL response body in Postman. Which test script correctly asserts that the 'posts' array inside 'user' has exactly 3 items?
Postman
{
"data": {
"user": {
"posts": [
{"id": "p1"},
{"id": "p2"},
{"id": "p3"}
]
}
}
}Attempts:
2 left
💡 Hint
Use the correct Chai assertion for array length in Postman.
✗ Incorrect
In Postman test scripts, to check array length, use 'to.have.lengthOf()'. Using '.length' property with 'to.eql()' works but is less idiomatic. The '.count' and '.size' properties do not exist on arrays.