In a GraphQL federated architecture, why do we use shared types across subgraphs?
Think about how multiple teams might work on different parts of a graph but need to share common data structures.
Shared types allow different subgraphs to refer to the same type, which helps keep data consistent and enables the gateway to stitch the schema correctly.
Given two subgraphs sharing a User type with a @key directive, what will this query return?
query {
user(id: "123") {
id
name
email
}
}Subgraph A defines User with fields id, name and @key(fields: "id"). Subgraph B extends User with field email. The gateway composes the schema and runs the query above.
Remember that the gateway merges fields from all subgraphs that share the same key.
The gateway merges the User type from both subgraphs using the @key directive, so the query returns all fields including email.
Identify the valid GraphQL schema snippet that correctly defines a shared Product type with a @key directive for federation.
Check the syntax for the @key directive and the type of the key field.
The @key directive requires the fields argument as a string. The key field must be non-nullable and the type must match usage. Option A correctly uses String! and quotes around upc.
When multiple subgraphs share a type, what is an effective way to optimize query performance at the gateway?
Think about how to minimize data transfer and processing by fetching only what is needed.
Entity resolvers allow the gateway to request only the fields needed from each subgraph, reducing data transfer and improving performance.
Given this subgraph schema snippet:
extend type Review @key(fields: "id") {
id: ID!
body: String
}And this query:
query {
review(id: "r1") {
id
body
}
}Why does the gateway return an error: Cannot find key fields for type 'Review'?
Consider what it means to extend a type without defining it first.
Extending a type requires that the base type be defined in at least one subgraph. Here, Review is only extended but never defined, so the gateway cannot find key fields.