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

ResolutionEnvironment as a hierarchy

Open chrisflatley opened this issue 7 years ago • 1 comments

Am I right in thinking you can only get the current resolution environment, not the parent or its parents. (And specifically the parent context?)

When you have a schema like:

query {
  datasource(name:wikipedia) {
    search {
      results {
        count
      }
    }
  }
}

It might be that count needs to access the search's and 'datasource' ResolutionEnvironment in order to run its own query.

Currently we are passing this down by returning a SearchNode from search which has the information on, then from results we return a ResultsNode which points back to SearchNode etc. That works but its a bit tedious to create all POJO which hold that type of info.

Is that something worth adding to ResolutionEnvironment.getParentResolutionEnvironment() [potentially null/optional.empty if at the root].

chrisflatley avatar Oct 27 '17 12:10 chrisflatley

Doing this in a nice way would require changes to graphql-java. I'll investigate a bit more and talk with the rest of the graphql-java team. But, it's entirely feasible in a non-nice way by maintaining a stack of DataFetchingEnvironments in the global context. SPQR already (ab)uses this method to transparently support clientMutationId so, while I'm not too keen on going that route, it's not much of stretch either.

kaqqao avatar Dec 15 '17 10:12 kaqqao