graphql-go icon indicating copy to clipboard operation
graphql-go copied to clipboard

Single root resolver to recursively resolve the full query

Open agnivade opened this issue 3 years ago • 6 comments

Hi,

I am investigating this library to be used in our project. From what I am seeing, we need to pass a resolver struct whose fields/methods map to the graphQL query, and the engine recursively calls each of its nested fields.

What I am looking to achieve is to have a single root resolver, and I want to access the query AST myself to construct the full response. The reason for this is to be able to dynamically generate efficient SQL queries joining multiple tables, rather than querying multiple times. Similar to what https://hasura.io/ does.

Is there a way to achieve that using this library?

agnivade avatar Nov 23 '21 04:11 agnivade

It seems that I just need access to the query package to get its AST and then execute the query by my own. But the query package is under internal right now, and more interestingly the AST it returns (types.ExecutableDefinition) is public. And the query package just has one function Parse.

I am wondering if we could make this public?

agnivade avatar Nov 25 '21 03:11 agnivade

@agnivade I am working on exposing the selected fields in each resolver as well as their child fields. This has been the most requested feature to the library ever. There has been several PRs so far and a few ideas how to implement this. I'll continue the work on this next week when I'm back home. I'd be happy to explain in more details in Slack.

pavelnikolov avatar Dec 08 '21 16:12 pavelnikolov

I agree that making the AST public would open some interesting opportunities.

pavelnikolov avatar Dec 08 '21 17:12 pavelnikolov

@agnivade you could now use schema.ASTSchema()

pavelnikolov avatar Feb 17 '23 11:02 pavelnikolov

After more careful reading, I realized that you are talking about the query and not the schema. This will most probably be added in v1.7.0.

pavelnikolov avatar Feb 17 '23 11:02 pavelnikolov

Thanks @pavelnikolov !

agnivade avatar Feb 18 '23 02:02 agnivade