ChilliCream / ChilliCream/graphql-platform

Cannot add Errors with MutationConventions via ITypeModule

Open
#6,723 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Type System
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
  1. Create a ITypeModule
  2. Add a mutation method ObjectFieldDefinition newField = new(<stuff>).ToDescriptor(context).UseMutationConvention().Error<AnError>().ToDefinition()
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.