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?
Remember that the gateway merges data from both services, so extended fields appear in the final response.
The gateway composes the schema so that the Product type includes fields from both services. The reviews field is added by the Reviews service, so the response includes it with nested author data.
In Apollo Federation, to indicate that a type or field is extended from another service, which directive must be used?
Think about how a service declares it is adding fields to a type defined elsewhere.
The @extends directive marks a type as an extension of a type defined in another service, enabling gateway composition.
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?
Check the braces carefully in the type definition.
The snippet is missing the closing brace '}' at the end of the type extension, causing a syntax error.
When a gateway composes multiple services, queries can become slow due to multiple network calls. Which approach best reduces latency?
Think about how to minimize the number of calls and reuse data.
Batching requests and caching results at the gateway reduces the number of network calls and speeds up query resolution.
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?
Check how fields from the base service are referenced in extensions.
In Apollo Federation, fields from the base service used in an extension must be marked with @external to indicate they come from another service. Without it, the resolver may not receive the correct value, causing null results.