-
Notifications
You must be signed in to change notification settings - Fork 322
Description
Describe the bug
Apollo Router v2.5.0 throws an internal error "Unexpectedly missing edge for __typename field" when executing queries that use inline fragments on interface objects. This occurs when querying interface objects from one subgraph and using inline fragments for interfaces defined in another subgraph, despite successful supergraph composition.
To Reproduce
Setup
- Create two subgraph definitions with the following schemas:
Subgraph A (subgraph_a.graphql
):
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@interfaceObject"]
)
type IVehicle @key(fields: "id", resolvable: false) @interfaceObject {
id: ID!
}
type ILandVehicle @key(fields: "id", resolvable: false) @interfaceObject {
id: ID!
}
type Query {
myVehicles_A: [IVehicle]!
}
Subgraph B (subgraph_b.graphql
):
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable", "@external", "@interfaceObject"]
)
interface IVehicle @key(fields: "id") {
id: ID!
color: String
}
interface ILandVehicle implements IVehicle @key(fields: "id") {
id: ID!
color: String
numberOfWheels: Int!
}
type Bike implements ILandVehicle & IVehicle @key(fields: "id") {
id: ID!
color: String
numberOfWheels: Int!
}
type Query {
myVehicles_B: [IVehicle]!
}
- Compose the supergraph using Rover:
rover supergraph compose --config ./supergraph_config.yaml --elv2-license=accept > ./supergraph.graphql
Supergraph config (supergraph_config.yaml
):
subgraphs:
graphA:
routing_url: http://localhost:4010
schema:
file: ./subgraphs/subgraph_a.graphql
graphB:
routing_url: http://localhost:4011
schema:
file: ./subgraphs/subgraph_b.graphql
- Start the Apollo Router:
./router --dev --supergraph supergraph.graphql
- Submit the following GraphQL query:
query Test {
myVehicles_A {
id
... on ILandVehicle {
color
}
}
}
Expected behavior
The query should execute successfully since:
- The supergraph composition succeeds without errors
- The generated supergraph contains all necessary type relationships
ILandVehicle
properly implementsIVehicle
in the federation schema- The inline fragment
... on ILandVehicle
is valid against theIVehicle
return type
Output
Error Response:
{
"errors": [
{
"message": "value retrieval failed: Federation error: An internal error has occurred, please report this bug to Apollo.\n\nDetails: Unexpectedly missing edge for __typename field",
"extensions": {
"code": "INTERNAL_SERVER_ERROR"
}
}
]
}
Note: The same query pattern works correctly when querying myVehicles_B
instead of myVehicles_A
, confirming that the issue is specifically related to interface objects rather than the general federation setup.
Desktop (please complete the following information):
- OS: macOS
- Apollo Router Version: 2.5.0
- Rover Version: 0.35.0 (used for composition)
Additional context
- The issue appears to be in the query planner's handling of
__typename
field resolution when dealing with interface objects and inline fragments - This is a valid federation pattern where one subgraph defines interface objects (stubs) and another defines the actual interface implementations
- The supergraph schema correctly shows the relationships between types with proper
@join__implements
directives - Adding
__typename
explicitly to the query does not resolve the issue - This error suggests an internal bug in the router's query planning logic rather than a schema composition issue
Minimal reproduction repository: The issue can be reproduced with just the two subgraph files and supergraph config shown above. No running subgraph servers are needed as this issue appears to occur in the query validation or exection planning stage.