Skip to content

Cannot add Errors with MutationConventions via ITypeModule #6723

Open
@cambirch

Description

@cambirch

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions