ChilliCream / ChilliCream/graphql-platform
Cannot add Errors with MutationConventions via ITypeModule
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Is there an existing issue for this?
- I have searched the existing issues
Product
Hot Chocolate
Describe the bug
When adding mutations via an ITypeModule you can register them using UseMutationConvention but if you call Error<>() afterwards it will throw in ObjectFieldDefinitionExtensions.cs on line 52 due to the MutationContextDataKeys.Options not being registered in the provided IDescriptorContext from the ITypeModule /or/ registered via a manual call to UseMutationConvention().
Steps to reproduce
- Create a ITypeModule
- Add a mutation method
ObjectFieldDefinition newField = new(<stuff>).ToDescriptor(context).UseMutationConvention().Error<AnError>().ToDefinition() - Fails
Relevant log output
No response
Additional Context?
This can be worked around by adding this to the top of the registration function (fixes the broken AddError lookup):
context.ContextData["HotChocolate.Types.Mutations.Options"] = new HotChocolate.Types.MutationConventionOptions
{
ApplyToAllMutations = true,
};
Version
13.7.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ObjectFieldDefinitionExtensions.cs line 52 and trace how UseMutationConvention() and Error() access MutationContextDataKeys.Options when building an ITypeModule field. Reproduce the ITypeModule registration from the issue, including the manual MutationConventionOptions workaround, and confirm that adding an error no longer throws without that workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100