Let’s say I have this schema:
# Service A
type Product @key(fields: "id") {
id: ID!
}
# Service B
extend type Product @key(fields: "id") {
id: ID! @external
foo: Int
bar: String!
}
type Review {
product: Product!
}
If Service B did not add any field to Product
, I’d just return a representation for Product
resolver in Review
like this:
(productId) => ({
type: "Product",
id: productId
})
However, here there are 2 additional fields foo
and bar
. These fields are resolved like this:
const resolvers = {
Product: {
foo: fooResolver,
bar: barResolver,
},
Review: {
product: (review) => ({ type: "Product", id: review.productId}) // do I need to add foo & bar resolvers?
}
}
The question is: do I need to add foo
& bar
resolvers when I’m returning the representation of Product?
In any case, I’m using graphql-codegen
to generate my resolvers types, and it compels me to do so. But I find very laborious to add all the fields resolvers anytime I’m returning a representation…
Any thought about this?