query result composition problem in graphQL gateway

78 views Asked by At

so we have a microservice architecture and there was a need for queries of different types from different microservices. so we implemented the graphQL gateway and it works and it is really good. but there was this peculiar need that is just driving me insane on how to do it. we are using nestjs and typeorm.

Problem: the problem is, we want to search on user entity which is in the person service and also on related entities to user on different services. for example let say i want users with the name like "john" who hadn't a payment (their userid doesn't exist on the records) in last week and haven't bought our latest product (again their userid not existing on the records) but purchased the one before that (their userid and payment id exists). as you see they are deeply connected. on top of that we want to show the final result with pagination and how many results matched it. as you can see the result of each filter is closely related to the other ones.

so i can easily make a root query on the users with the filter of name "john" then have a query inside it of orphan type userPayment which queries payment and also the product one (all being handled by federation) and in the frontend just filter the result of the ones which these fields are empty. but the thing is, my pagination and view gets messed up, the total count for pagination comes from the root users query and the other two queries are run for each of matching users.

so the question is how can you make a query like this ? i searched around and heard about CQRS but isn't there another approach besides duplicating data and one database and stuff ? also since we are using the typescript i cannot query each one and hold all their data in code. if 10000 users were found, javascript simply runs out of heap memory.

what do you suggest?

0

There are 0 answers