Skip to content

AnyType serialization does not support Dictionary with empty string key #9774

@stanislav-a-frolov

Description

@stanislav-a-frolov

Product

Hot Chocolate

Version

16.0.9

Link to minimal reproduction

https://github.com/stanislav-a-frolov/TestEmptyDictionaryKeys

Steps to reproduce

  1. Setup executor with query field resolving to dictionary with empty string key, add type converter to JsonElement
        var executor = await new ServiceCollection()
            .AddGraphQL()
            .AddQueryType(q => q.Field("data").Resolve(ctx => new Dictionary<string, object?>() { { "", 1 } }).Type<AnyType>())
            .AddTypeConverter<Dictionary<string, object?>, JsonElement>(value => JsonSerializer.SerializeToElement(value))
            .BuildRequestExecutorAsync();
  1. Execute query, get errors
        var response = await executor.ExecuteAsync("query { data }");
        var operationResult = response.ExpectOperationResult();
        Assert.Empty(operationResult!.Errors); // fail: Value cannot be null. (Parameter 'propertyName')

What is expected?

Result is expected to be serialized with empty string field without errors as it was in HC 15

What is actually happening?

ArgumentNullException is thrown at ResultElement.SetPropertyName due to empty span

Relevant log output

Additional context

No response

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions