I have 4 individual microservices and a dashboard that has 5 tabs. Each tab corresponds to data from the four services, with the fifth tab being a consolidated list of the other four. Each tab has the same set of fields and there is no key to relate the 4 services.
Currently each of the 4 services are defined as independent Graphql queries as separate types and I use a custom Graphql query that just has the 4 other queries to fetch all data.
Is it better to keep it this way, or should I remove the individuals and just define one query type that fetches all data?
I realize this is an old post, but I have dealt with a similar situation where I source data from multiple places so maybe this will help someone else.
This type of design decision requires more background on the data you’re modeling. I can’t answer it definitively. If the data is coming from four services, and you have a reason to break it into four different tabs on a UI, it leads me to think these could warrant the different queries and types you have defined.
Here are some questions I’ve asked myself to help clarify design choices like this:
- Do the things from the four services truly represent the “same thing”, or do they just have a few similar properties right now? (or are you shoe-horning them to fit the same schema?)
- As development continues, will the types diverge over time? If so, defining separate queries that return separate types will be easier to build on.
- Is it useful from the client side to get one unified list of “things”? You can use union types, but they’re kind of a pain from the client side. If you don’t really need that ability, having separate queries and separate types is easier to deal with on both sides.