Open enisdenjo opened 6 months ago
Can fields have multiple same-source resolvers too?
wdym here?
Can a field have multiple resolvers on the same field. Like this:
type Query {
manufacturer(id: ID!): Manufacturer
@resolver(
subgraph: "manufacturers"
operation: "query manufacturer($id: ID!) { manufacturer(id: $id) { ...export } }"
)
@resolver(
subgraph: "manufacturers"
operation: "query manufacturerById($id: ID!) { manufacturerById(id: $id) { ...export } }"
)
@source(
subgraph: "manufacturers"
name: "manufacturer"
type: "Manufacturer"
)
}
In the Composite Schema WG proposal, there could be infinite number (as of today).
# subgraph
type Query {
userById(id: ID! @is(field: "id"): User @lookup
userByUuid(id: ID! @is(field: "uuid"): User @lookup
usersByIds(ids: [ID!]! @is(field: "id")): [User] @lookup
user(id: ID! @is(field: "id")): User @lookup @lookup
}
type User @key(fields: "id") @key(fields: "uuid") {
id: ID!
uuid: ID!
name: String!
}
In Federation there's only one endpoint Query._entities
.
Ok cool, so yes.
Curious on the rationale here...
For example, if there is a resolver that accepts an array of IDs argument - it should be preferred when resolving multiple same-type items.
If there's a list available over a single record query, seems like the list is always preferable; it makes for smaller documents that are always consistent regardless of number of records loaded, etc. So, is there a case for dynamic selection of the resolver query? Otherwise, IMO it just adds a vector of confusion over how a query is resolving when there are multiple pathways.
The gatherer should decide which one is the best to use.
For example, if there is a resolver that accepts an array of IDs argument - it should be preferred when resolving multiple same-type items.
Q: Can fields have multiple same-source resolvers too? A: Yes.