Hi guys,
At the summit in one of the Federation From Day One workshops, I asked a question about how one would go about returning a list of all reviews for a location that were over 3 stars. I was told it was out of scope for the demo, and I unfortunately did not have time to follow up in person so I am doing so here.
I took a stab at adding a couple of fields to the Location service.
type Location @key(fields: "id")
id: ID!
<snip>
reviewsForLocation: [Review]! @external
reviews: [Review!]! @requires(fields: "reviewsForLocation { ... on Review { rating } }")
}
type Review @key(fields: "id") {
id: ID!
rating: Int @external
}
This composes just fine, but when I try to execute the following query, I get some strange behavior
query Locations {
locations {
id
name
description
reviews {
rating
comment
}
}
}
There are subgraph errors redacted, and then it complains about returning null for non-nullable field location
…
But most strikingly, the query plan has this step:
Flatten(path: "locations.@") {
Fetch(service: "locations") {
{
... on Location {
__typename
reviewsForLocation {
id
rating
}
id
}
} =>
{
... on Location {
reviews {
__typename
id
}
}
}
},
},
This feels wrong. Why are we fetching for reviewsForLocation
from the locations service? The rating
field is marked as @external
and the locations service can’t resolve it, the entire reviewsForLocation
field is marked as @external
. Furthermore, @requires
against a local field doesn’t work (though I would love that feature).
The field resolvers are reporting some strange things as well. The reviews service is receiving requests for reviewsForLocation
, and is resolving them correctly, but the field resolver for reviews
on the location service does not have the field at all on the parent.
Is this working as intended? How am I supposed to do this if so?
I have attempted several minor tweaks of this (resolvable: false on the Review type, not using an inline fragment in requires) and get the same result.