graphql-go / graphql-go/graphql

Modifying Context during a resolve function to transfer data down a tree

Open
#156 3 comments 9 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

If, for example, you had some query like:

```
first {
second {
third {
a
b
c
}
}
}
```

And during the resolve function for `first` you want to carry over some data for `third` to use during resolution you might think you could do something like:

``` go
params.Context = context.WithValue(params.Context, someContextKey, someValue)
```

But of course this won't work at all. I think it might be worth finding a way to allow something like this to happen, otherwise it would seem that `third` has to always be built in such a way that it can't know anything about the tree it's being requested from other than through arguments (and if you're having to repeat the same argument per tier that might become problematic).

I'm not sure if the graphql-js "root value" solution allows this to happen (and if it doesn't, then I suppose there is no reason for this project too) it just seems useful.

What are your thoughts about this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.