1

With a federated GraphQL model using Apollo, the docs state that "A reference resolver is responsible for returning all of the entity fields that this subgraph defines". But is it possible to have fields in a subgraph not returned from the __resolveReference function, which have their own separate resolvers?

For example, let's say this is the schema (in two subgraphs):

// Products subgraph
type Product @key(fields: "id") {
  id: ID!
  name: String!
  price: Int
}


// Inventory subgraph
type Product @key(fields: "id") {
  id: ID!
  inStock: Boolean!
  otherField: String!
}

Can you then have this in your resolvers in the inventory subgraph?

// Inventory subgraph
const resolvers = {
  Product: {
    __resolveReference({ id }) {
      return { id, inStock: false };
    },
    otherField: () => 'Hello World!',
  },
}
nerdlinger
  • 1,610
  • 2
  • 17
  • 24
  • I am also interested in this question - in many cases, it would be the preferable design choice to have fields resolved only as needed. Apollo Server seems to permit it, but the statement from the documentation has me worried. One theory I have is that the docs were hastily written, and what they really mean is: "the reference resolver is responsible for returning all fields that do not have their separate resolvers defined" - that would make sense. – elias.hj Feb 23 '23 at 13:36

0 Answers0