Bird
0
0

Given the schema:

medium📝 query result Q4 of 15
GraphQL - Type Relationships
Given the schema:
type Customer { id: ID name: String orders: [Order] } type Order { id: ID total: Float customer: Customer }

What will the query
{ customer(id: "5") { name orders { id total } } }
return assuming customer 5 has two orders?
AOnly the customer's name without any orders
BThe customer's name and a list of their two orders with id and total
CAn error because orders cannot be queried inside customer
DA list of all orders in the system regardless of customer
Step-by-Step Solution
Solution:
  1. Step 1: Understand the schema

    Customer has a one-to-many relationship with orders via the 'orders' field.
  2. Step 2: Analyze the query

    The query requests the customer's name and their orders' id and total.
  3. Step 3: Determine expected result

    Since customer 5 has two orders, both orders' details will be returned along with the name.
  4. Final Answer:

    The customer's name and a list of their two orders with id and total -> Option B
  5. Quick Check:

    Nested fields return related data [OK]
Quick Trick: Nested fields return related lists [OK]
Common Mistakes:
  • Assuming orders field cannot be queried
  • Expecting only customer data without orders
  • Thinking query returns all orders regardless of customer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes