Bird
0
0

Given this mutation:

medium📝 query result Q13 of 15
GraphQL - Mutations
Given this mutation:
mutation { updatePost(id: "5", input: {title: "New Title"}) { id title content } }

What will be the output if the post with ID 5 exists and has content "Old content"?
A{ "data": { "updatePost": null } }
B{ "data": { "updatePost": { "id": "5", "title": "Old Title", "content": "Old content" } } }
C{ "data": { "updatePost": { "id": "5", "title": "New Title", "content": "Old content" } } }
DError: Post with ID 5 not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand the mutation effect

    The mutation updates the post with ID 5, changing only the title to "New Title" while keeping other fields unchanged.
  2. Step 2: Predict the returned data

    The response includes the updated title and the unchanged content "Old content" along with the ID.
  3. Final Answer:

    { "data": { "updatePost": { "id": "5", "title": "New Title", "content": "Old content" } } } -> Option C
  4. Quick Check:

    Update mutation returns updated fields plus unchanged fields [OK]
Quick Trick: Update changes specified fields, others remain same [OK]
Common Mistakes:
  • Assuming all fields reset or become null
  • Expecting error when post exists
  • Ignoring unchanged fields in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes