0
0
GraphQLquery~20 mins

Gateway composition in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gateway Composition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the result of this federated query?

Given two GraphQL services composed via a gateway, the Product type is extended in the Reviews service. Consider the following query executed against the gateway:

{ product(id: "1") { id name reviews { body author { name } } } }

Assuming the Product service returns { id: "1", name: "Table" } and the Reviews service returns two reviews with authors, what is the expected shape of the response?

A{"data":{"product":{"id":"1","name":"Table"}}}
B{"data":{"product":{"id":"1","name":"Table","reviews":[{"body":"Great!","author":{"name":"Alice"}},{"body":"Good quality","author":{"name":"Bob"}}]}}}
C{"data":{"product":{"id":"1","reviews":[{"body":"Great!","author":{"name":"Alice"}},{"body":"Good quality","author":{"name":"Bob"}}]}}}
D{"errors":[{"message":"Field 'reviews' not found on type 'Product'"}]}
Attempts:
2 left
💡 Hint

Remember that the gateway merges data from both services, so extended fields appear in the final response.

🧠 Conceptual
intermediate
1:30remaining
Which directive is essential for gateway composition in Apollo Federation?

In Apollo Federation, to indicate that a type or field is extended from another service, which directive must be used?

A@external
B@key
C@extends
D@provides
Attempts:
2 left
💡 Hint

Think about how a service declares it is adding fields to a type defined elsewhere.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this federated schema snippet

Consider this schema snippet from a federated service:

extend type User @key(fields: "id") { id: ID! name: String! @external posts: [Post] }

What is the syntax error here?

AMissing closing brace '}' for the type definition
BMissing @external directive on 'posts' field
CThe @key directive must be on the base type, not on an extension
DThe 'posts' field must have a non-nullable type
Attempts:
2 left
💡 Hint

Check the braces carefully in the type definition.

optimization
advanced
1:30remaining
How to reduce query latency in gateway composition?

When a gateway composes multiple services, queries can become slow due to multiple network calls. Which approach best reduces latency?

AIncrease the timeout for each subservice request
BRemove @key directives to simplify schema
CDisable schema stitching and use separate endpoints
DBatch requests to subservices and cache results at the gateway
Attempts:
2 left
💡 Hint

Think about how to minimize the number of calls and reuse data.

🔧 Debug
expert
2:30remaining
Why does this federated query return a null for an extended field?

A federated gateway query requests an extended field reviews on Product. The base service returns the product data correctly, but reviews is always null. The Reviews service schema has:

extend type Product @key(fields: "id") { id: ID! reviews: [Review] }

And the resolver for reviews uses the id from the parent. What is the most likely cause?

AThe <code>id</code> field is not marked with @external in the extension
BThe <code>Product</code> type is not marked with @extends in the Reviews service
CThe <code>reviews</code> field is missing the @requires directive
DThe gateway is not forwarding headers to the Reviews service
Attempts:
2 left
💡 Hint

Check how fields from the base service are referenced in extensions.