enisdenjo / graphql-composite

Spec agnostic GraphQL composite schema planner, executor and explainer.
MIT License
7 stars 0 forks source link

Types and fields can have multiple resolvers for the same source #6

Open enisdenjo opened 6 months ago

enisdenjo commented 6 months ago

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.

kamilkisiela commented 6 months ago

Can fields have multiple same-source resolvers too?

wdym here?

enisdenjo commented 6 months ago

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"
    )
}
kamilkisiela commented 6 months ago

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.

enisdenjo commented 6 months ago

Ok cool, so yes.

gmac commented 1 month ago

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.