We are currently building an ASP.NET Core 8 Web API that will get a big GraphQL request for our new website's homepage. Now that homepage needs to display information that then comes from various other third party APIs. All these APIs will also be called through GraphQL client.
My question is how to parse relevant parts from the original big GraphQL request and construct these new GraphQL requests for these third party APIs (especially the fields). For my POC, I have just hardcoded these queries that I then use to call these third party APIs. After receiving the data I use the resolver of the original big GraphQL request and populate the data and then return the response.
The problem with this approach is that I am over fetching because if the original big GraphQL request doesn't has some fields then I will be still getting it anyway from the downstream third party APIs.
The incoming GraphQL request does have a schema but the request structure can be different depending on form factor (device / web browser etc.)
I have looked into HotChocolate's IResolverContext
or GraphQL.NET's AST parser but the code quickly became quite messy because the request structure is quite variable even though we know the schema.
I would like to know if I am missing something here as I am new to GraphQL (with mainly REST experience only) and there is like a standard way to do it?
This problem is already solved :) There is HotChocolate Fusion which is a GraphQL Gateway. Here are the docs: https://chillicream.com/docs/fusion/v15
Building a GraphQL server based on just a parser on your own is a major undertaking. GraphQL has very different guarantees from REST and needs an execution engine. So a simple parser does not help. Also if you are trying to implement a GraphQL Gateway this is a major undertaking and you have to think about what algorithm you will use to slice requests and avoid an N+1 problem. But apart from that you have to think about a whole lot of other issues like how entities are declared and composed.