-
Notifications
You must be signed in to change notification settings - Fork 307
Open
Labels
Description
Describe the bug
Under certain circumstances, the @requires
directive behaves unexpectedly. The router incorrectly asks subgraph for both:
- The target field annotated with
@requires
- The dependent fields specified in the
@requires
directive
To Reproduce
User subgraph:
type Query {
myUser: User
}
type User @key(fields: "id") {
id: Int!
productStats: ProductStats
suitableProductsCount: Int @requires(fields: "productStats { productMeta { cost } }")
}
type ProductStats @key(fields: "id", resolvable: false) {
id: Int!
productMeta: ProductMeta @shareable
}
type ProductMeta {
cost: Int @external
userRating: Int
}
Stats subgraph:
type ProductStats @key(fields: "id") {
id: Int!
productMeta: ProductMeta @shareable
}
type ProductMeta {
cost: Int @shareable
}
Request:
query MyQuery {
myUser {
suitableProductsCount
}
}
What router sends to user subgraph:
query MyQuery__user__0 { myUser { productStats { productMeta { cost } } suitableProductsCount } }
Expected behavior
- router sends request to user subgraph and asks for
{ myUser { id productStats { id } }
. - Then, the entity resolver for
ProductStats
is used to obtaincost
from stats subgraph. - And then the entity resolver for
User
is used to calculatesuitableProductsCount
.
Output
I tried to fix this by markingproductMeta: ProductMeta
as @external
in user subgraph and writing @provides(fields: "productMeta { userRating }")
. However, it didn't work.
If I move userRating
to another place and mark productMeta: ProductMeta
as @external
, then it works.
If productMeta
is not marked as @external
, then it still doesn't work.
Desktop (please complete the following information):
- OS: macOS
- Version 15