-
I'm quite new to GraphQl and have a question about something. Every example I see has the same structure, a Entity e.g. Show and another Entity Review where a show has multiple reviews. I implemented this as a Customer and Order entity where a customer can have multiple orders. I created two separate services: CustomerService and OrderService both created with DGS framework. And a apollo-server with apollo-gateway which consumes the graphql endpoints. Following schemas:
This works fine and I can query customers with their orders. What I want is to be able to also query orders with the customer information. But I have a hard time to find any documentation about how to do that. Can someone point me in the right direction? What I think I need to do is add a customer: Customer to the Order type, but I don't know how to write the data fetcher for that. Or is this totally against the idea of GraphQl and should I not implement it this way, if so what is the best way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@timpie90 Welcome to the GraphQL world! We are happy to help with any DGS specific questions, but from what I can understand your question is more centered around Apollo Federation. They have some great docs around this: https://www.apollographql.com/docs/federation/federated-types/overview, as well as repos: https://github.com/apollographql/federation-jvm and https://github.com/apollographql/apollo-federation-subgraph-compatibility. What I can say upon looking at your schema is that you can leverage Apollo directives like As far as data fetchers are concerned, make sure that they are set up accordingly to fetch the necessary data from the underlying data sources (e.g., databases) based on the customerId field in the Order service and the id field in the Customer service, for example. You can find more info on datafetching here. I am going to close this issue for now, but please feel free to open a new one if you have any DGS framework questions. |
Beta Was this translation helpful? Give feedback.
@timpie90 Welcome to the GraphQL world! We are happy to help with any DGS specific questions, but from what I can understand your question is more centered around Apollo Federation. They have some great docs around this: https://www.apollographql.com/docs/federation/federated-types/overview, as well as repos: https://github.com/apollographql/federation-jvm and https://github.com/apollographql/apollo-federation-subgraph-compatibility.
What I can say upon looking at your schema is that you can leverage Apollo directives like
@provides
and@requires
(https://www.apollographql.com/docs/federation/federated-types/federated-directives#provides) to tell the gateway where to fetch data from. But …