ServiceKind isn't correctly respected by resolvers added to field descriptors using the code-first approach #4945
Labels
🐛 bug
Something isn't working
🌶️ hot chocolate
🔍 investigate
Indicates that an issue or pull request needs more information.
📌 pinned
Milestone
Is there an existing issue for this?
Describe the bug
When adding a resolver using
IObjectFieldDescriptor.ResolveWith<T>
that uses a service registered with aServiceKind
other thanServiceKind.Default
, the resolver either runs with the incorrect execution strategy or completely fails to obtain the dependency.Specifically:
System.Random
does not exist oncontext.ScopedContextData
"System.Random
does not exist oncontext.ScopedContextData
"If you take those same methods and place them directly in an object or in an object extension, then everything works as expected.
Steps to reproduce
I've created a gist that has the following code as well as all of the necessary boilerplate. You can find it here: Program.cs.
Register
Random
in a service collection as a scoped service.Register an
ObjectPool<Random>
in a service collection as a scoped service. (The implementation can be naive and just return a new instance of Random each time.)Create a QueryType that relies on injecting Random using a code-first approach:
Register the
QueryType
as the query type andRandom
as service using a any of the non-defaultServiceKind
s:Execute the following GraphQL query:
Relevant log output
No response
Additional Context?
I originally found this issue while trying to troubleshoot concurrency exceptions thrown by
DbContext
. Although I'm demonstrating the issue with just plain old services to keep things a bit simpler, the issue affects more than justRegisterService
.Specifically, it seems this issue affects any parameters that rely on
IParameterFieldConfiguration
.It looks like this is happening because
ObjectFieldDescription.CompleteArguments
checksParameters.Count > 0
before applying configurations, but because the field was created usingdescriptor.Field(...)
rather than using a method, there aren't actually any parameters so the configuration is never applied.This results in:
I also ran into similar issues with node resolvers, but that doesn't seem to be strictly related to this issue. It would be nice if those were looked into as well, but I haven't researched them as thoroughly.
Product
Hot Chocolate
Version
12.7.0
The text was updated successfully, but these errors were encountered: