0
0
Postmantesting~20 mins

GraphQL body in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Body Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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 } }"
}
A{"data":{"user":{"name":"Alice"}}}
B{"error":"User not found"}
C{"data":{"user":{"name":"Alice","age":30}}}
D{"data":{"user":null}}
Attempts:
2 left
💡 Hint
The query requests both name and age fields for user with id 123.
assertion
intermediate
2: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
});
Apm.expect(jsonData.user.email).to.eql('user@example.com');
Bpm.expect(jsonData.data.user.email).to.eql('user@example.com');
Cpm.expect(jsonData.data.email).to.eql('user@example.com');
Dpm.expect(jsonData.data.user.email).to.equal('user@example.org');
Attempts:
2 left
💡 Hint
The GraphQL response nests user inside data.
locator
advanced
2: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"}
      ]
    }
  }
}
A$.data.user.posts
B$.user.posts
C$.data.posts
D$.posts
Attempts:
2 left
💡 Hint
The 'posts' array is inside 'user', which is inside 'data'.
🔧 Debug
advanced
2: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 } }"
}
AThe query keyword is missing
BThe age field is not allowed in the query
CThe braces around user are incorrect
DThe user id 123 should be a string with quotes: \"123\"
Attempts:
2 left
💡 Hint
GraphQL requires string arguments to be quoted.
framework
expert
3: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"}
      ]
    }
  }
}
Apm.test('Posts count is 3', () => { const jsonData = pm.response.json(); pm.expect(jsonData.data.user.posts).to.have.lengthOf(3); });
Bpm.test('Posts count is 3', () => { const jsonData = pm.response.json(); pm.expect(jsonData.data.user.posts.length).to.eql(3); });
Cpm.test('Posts count is 3', () => { const jsonData = pm.response.json(); pm.expect(jsonData.data.user.posts.count).to.eql(3); });
Dpm.test('Posts count is 3', () => { const jsonData = pm.response.json(); pm.expect(jsonData.data.user.posts.size).to.eql(3); });
Attempts:
2 left
💡 Hint
Use the correct Chai assertion for array length in Postman.