So I have a few services that provide Product
data but this services has separate data stores. Is possible to query a specific service depending on field value?
I describe problem with the GQL below.
##
# This is supergraph
##
# Unique ID is `service` and `id` pair. But there is no single service
# that has access to all data to provide this information.
type Product @shareable @key(fields: "service id") {
service: String! # This can be enum if needed or even could be skipped
id: String!
name: String!,
owner: String!,
}
type RespServiceA @shareable {
# (...) some other fields
product: Product!
}
# ServiceA is from service-a subgraph and use different dataset than service-b
type ServiceA {
# This will always return `A` (the name of service)
name: String!
# This should be called only when service = 'A'
products_by_id(id: String) -> [Product]!
# now here router has a hard task as there is a `Product` inside `ProductWrapper`
# and the Product should be resolved by `ServiceA` or `ServiceB` depending on `Product.service` value
#
# in my scenario `RespServiceA.product` will alway be from ServiceA::products_by_id
complex_query(query_parmeter: String!) -> [RespServiceA]!
}
# ServiceB is from service-b subgraph and use different dataset than service-a
type ServiceB {
# This will always return `B` (the name of service)
name: String!
# This should be called only when service = 'B'
products_by_id(id: String) -> [Product]!
# similar `complex_query` as in ServiceA but returns RespServiceB
}
type Query (
service_a: ServiceA!
service_b: ServiceB!
)