Hi, new to GraphQL and am currently fiddling with Apollo Federation.
Using a minimal example, I have a product service and a review service.
In my product service, I define the product type and its resolver
type Product @key(fields: "id") {
id: ID!
name: String!
}
*__resolveReference impl*
In my review service, I define the following
type Review {
id: ID!
product: Product!
comment: String!
}
type Product @key(fields: "id", resolvable: false) {
id: ID!
}
type Mutation {
addReview(productId: ID!): Review!
}
And the mutation resolver
addReview: (args) => {
...insert into db in the form (id, productId, comment)
return { ... };
}
At this point, everything works fine since the federated graph will automatically resolve the product field of the Review by querying the product service.
My question now is what if I want to first validate that the productId
provided to addReview
actually exists in the product db managed the the product service?
- Is there a way of designing the schema to resolve this automatically?
- If not, it seems like I would need some form of inter-service communication, where I must call the product service from within the
addReview
resolver to check that theproductId
exists. In this case, are there any standard methods for how this is implemented?