User RootResolver Factory instead of creating it once #2783
arthurvaverko
started this conversation in
Ideas
Replies: 1 comment
-
bump ... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
from the docs
while it is great to have a place for dependencies on the root resolver the main drawback is
It gets initialized once in server.go when we create the graph.
using golang its easy to init something once using
sync.Once
while initializing something per-request is much harder and in many cases is implemented using
context.Context
injection of values.Generally the community convention is against using context for DI one ref can be found here
My suggestion is to add a
ResolverRootFactory
to the generated config sturctthen the generated code that is creating the resolver from the executable schema will create it using the Request Context.
this way we can inject loggers per request with some contextual information or DataLoaders or any other per-request dependencies and pass the explicitly to all other resolvers including Query, Mutation or any Type resolver.
I was wondering if thats something that only i find as required ?
how do you deal with per-request dependencies ? do you use context? or is there any other approach?
Beta Was this translation helpful? Give feedback.
All reactions