From 40bfe5533dbb6ce1ee2105b90804a5913f591eaf Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Fri, 27 Feb 2026 20:52:45 +0000 Subject: [PATCH 1/2] Fix #7919 dictionary-derived object type runtime binding --- .../src/Types/Configuration/TypeRegistrar.cs | 5 +- .../Regressions/Issue7919ProbeTests.cs | 112 ++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/HotChocolate/Core/test/Types.Tests/Regressions/Issue7919ProbeTests.cs diff --git a/src/HotChocolate/Core/src/Types/Configuration/TypeRegistrar.cs b/src/HotChocolate/Core/src/Types/Configuration/TypeRegistrar.cs index b71ee972f98..a6e573c24bb 100644 --- a/src/HotChocolate/Core/src/Types/Configuration/TypeRegistrar.cs +++ b/src/HotChocolate/Core/src/Types/Configuration/TypeRegistrar.cs @@ -78,7 +78,10 @@ public void Register( } MarkResolved(runtimeTypeRef); - _typeRegistry.TryRegister(runtimeTypeRef, registeredType.References[0]); + _typeRegistry.TryRegister( + runtimeTypeRef, + registeredType.References[0], + explicitBinding: RuntimeTypeBindingHelper.RequiresExactBinding(runtimeTypeRef.Type)); } private void RegisterTypeAndResolveReferences(RegisteredType registeredType) diff --git a/src/HotChocolate/Core/test/Types.Tests/Regressions/Issue7919ProbeTests.cs b/src/HotChocolate/Core/test/Types.Tests/Regressions/Issue7919ProbeTests.cs new file mode 100644 index 00000000000..164ceba9de4 --- /dev/null +++ b/src/HotChocolate/Core/test/Types.Tests/Regressions/Issue7919ProbeTests.cs @@ -0,0 +1,112 @@ +using HotChocolate.Execution; +using HotChocolate.Types; +using Microsoft.Extensions.DependencyInjection; + +namespace HotChocolate.Regressions; + +public class Issue7919ProbeTests +{ + [Fact] + public async Task Dictionary_Derived_Object_Uses_Metadata_As_Resolver_Parent() + { + // arrange + var executor = + await new ServiceCollection() + .AddGraphQLServer() + .AddQueryType() + .AddType() + .AddType() + .BuildRequestExecutorAsync(); + + // act + var result = await executor.ExecuteAsync( + """ + query { + metadata { + all { + key + value + } + key1: value(key: "key1") + key2: value(key: "key2") + key3: value(key: "key3") + } + } + """); + + // assert + var operationResult = result.ExpectOperationResult(); + Assert.Empty(operationResult.Errors ?? []); + result.MatchInlineSnapshot( + """ + { + "data": { + "metadata": { + "all": [ + { + "key": "key1", + "value": "value1" + }, + { + "key": "key2", + "value": "value2" + } + ], + "key1": "value1", + "key2": "value2", + "key3": null + } + } + } + """); + } + + public sealed class Query + { + public Metadata GetMetadata() + => new() + { + ["key1"] = "value1", + ["key2"] = "value2" + }; + } + + public sealed class Metadata : Dictionary; + + public sealed class MetadataType : ObjectType + { + protected override void Configure(IObjectTypeDescriptor descriptor) + { + descriptor.BindFieldsExplicitly(); + + descriptor + .Field("all") + .Type>>>() + .Resolve( + ctx => ctx.Parent() + .Select(e => new MetadataEntry(e.Key, e.Value.ToString()!))); + + descriptor + .Field("value") + .Argument("key", a => a.Type>()) + .Type() + .Resolve( + ctx => ctx.Parent() + .TryGetValue(ctx.ArgumentValue("key"), out var value) + ? value?.ToString() + : null); + } + } + + public sealed record MetadataEntry(string Key, string Value); + + public sealed class MetadataEntryType : ObjectType + { + protected override void Configure(IObjectTypeDescriptor descriptor) + { + descriptor.BindFieldsExplicitly(); + descriptor.Field(t => t.Key); + descriptor.Field(t => t.Value); + } + } +} From 9004a7061b4fb5edd68862471c8b6a6210fcfd86 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Thu, 5 Mar 2026 07:50:36 +0000 Subject: [PATCH 2/2] fix snapshot --- ...UseDataLoader_Should_ThrowException_When_NotADataLoader.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HotChocolate/Core/test/Execution.Tests/Integration/DataLoader/__snapshots__/UseDataLoaderTests.UseDataLoader_Should_ThrowException_When_NotADataLoader.snap b/src/HotChocolate/Core/test/Execution.Tests/Integration/DataLoader/__snapshots__/UseDataLoaderTests.UseDataLoader_Should_ThrowException_When_NotADataLoader.snap index 31655be4474..1ab14937798 100644 --- a/src/HotChocolate/Core/test/Execution.Tests/Integration/DataLoader/__snapshots__/UseDataLoaderTests.UseDataLoader_Should_ThrowException_When_NotADataLoader.snap +++ b/src/HotChocolate/Core/test/Execution.Tests/Integration/DataLoader/__snapshots__/UseDataLoaderTests.UseDataLoader_Should_ThrowException_When_NotADataLoader.snap @@ -9,5 +9,5 @@ For more details look at the `Errors` property. at HotChocolate.Execution.Integration.DataLoader.UseDataLoaderTests.<>c.b__0_1(IObjectTypeDescriptor`1 x) in UseDataLoaderTests.cs:line 16 at HotChocolate.Types.ObjectType`1.CreateConfiguration(ITypeDiscoveryContext context) in ObjectType~1.cs:line 47 at HotChocolate.Types.TypeSystemObject`1.Initialize(ITypeDiscoveryContext context) in TypeSystemObjectBase~1.cs:line 29 - at HotChocolate.Configuration.TypeRegistrar.InitializeType(TypeSystemObject typeSystemObject, String scope, Boolean isInferred) in TypeRegistrar.cs:line 171 + at HotChocolate.Configuration.TypeRegistrar.InitializeType(TypeSystemObject typeSystemObject, String scope, Boolean isInferred) in TypeRegistrar.cs:line 174