How to read the original query document is Absinthe?


Is it possible to access the original GraphQL query document (as a string) from a resolver function?

The resolution struct contains all information needed to reconstruct the query but it would be simpler to just use the one the client submitted.

Hi @sandorbedo can you elaborate regarding your use case?


In order to generate a reply for some of the queries in my app, I need to connect to another GraphQL server and forward/proxy the original query. Right now I build the query document up from the resolution struct, which is error prone.

a) It would be great to have a function in absinthe that converts the resolution into the query document.

b) Another solution I was thinking about is to use a plug early in the plug chain, that takes the original query document out and saves it somewhere. THis has two downsides: 1) since I have no abbess to the Plug.Conn struct, it’s hard to figure out where to save tha query string. Another problem is that it would be difficult to do for all the possible input methods (the documents coming from playground Absinthe.Plug.GraphiQL, the normal HTTP POST based Absinthe.Plag queries and the websocket based ones from Absinthe.GraphqlWS).

So basically the question is: how can I get the original query document in the resolver? This is needed to forward it to another GraphQL server based on certain conditions.

During document execution an intermediate representation of the document is available in the Absinthe.Blueprint struct, specifically the input. This represantation supports the Inspect protocol so it can be converted back to the string representation using inspect(blueprint.input, pretty: true).