Bird
0
0

Consider the following GraphQL query:

medium📝 Predict Output Q4 of 15
Rest API - REST API Fundamentals
Consider the following GraphQL query:
{ product(id: "456") { id name price } }
What data structure will the server return if the product exists?
A{"error": "Product not found"}
B{"data": {"product": {"id": "456", "name": "Laptop", "price": 1200}}}
C{"data": {"product": null}}
D{"data": {"product": {"id": "456", "name": "Laptop"}}}
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the query

    The query requests the product with id "456" and fields id, name, and price.
  2. Step 2: Understand GraphQL response format

    GraphQL returns data inside a "data" object with the requested fields if the product exists.
  3. Final Answer:

    {"data": {"product": {"id": "456", "name": "Laptop", "price": 1200}}} -> Option B
  4. Quick Check:

    Response includes all requested fields and no errors [OK]
Quick Trick: GraphQL returns requested fields inside 'data' if resource exists [OK]
Common Mistakes:
  • Confusing error response with data response
  • Assuming partial fields are returned if requested
  • Expecting null instead of error when resource exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes