graphql-dotnet / graphql-client

A GraphQL Client for .NET Standard
MIT License
612 stars 130 forks source link

Extract requested fields from query/response #580

Open StefanKoenigMUC opened 1 year ago

StefanKoenigMUC commented 1 year ago

Hi there,

I would like to ask if there is an easy way to access requested fields from an executed query?

My processing looks like that:

1) receive query-string from external source 2) create GraphQLRequest(string) 3) client.SendQueryAsync<Dictionary<string, object>>(graphqlRequest)

For some reason I need the data which was requested, if the query returns data its quite easy (as I may use the json to derive fields from), but I now need that also for the case that no data is returned.

Thanks in advance, Stefan

rose-a commented 1 year ago

You mean get a parsed representation of the query string on the client side?

There is currently no such functionality inside the client, it just passes the query string to the server as string. Maybe you can utilize some functionality of GraphQL.NET to parse the query on the client side for your purposes. (Maybe start looking here, that's where it turns the query string into an object...)

StefanKoenigMUC commented 1 year ago

tried now a different path - using the GraphQl-Parser and reconstructing it from the AST. May be a bit over the top, but is working now quite efficient.