Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ For more details look at the `Errors` property.
at HotChocolate.Execution.Integration.DataLoader.UseDataLoaderTests.<>c.<UseDataLoader_Should_ThrowException_When_NotADataLoader>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

Original file line number Diff line number Diff line change
@@ -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<Query>()
.AddType<MetadataType>()
.AddType<MetadataEntryType>()
.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<string, object>;

public sealed class MetadataType : ObjectType<Metadata>
{
protected override void Configure(IObjectTypeDescriptor<Metadata> descriptor)
{
descriptor.BindFieldsExplicitly();

descriptor
.Field("all")
.Type<NonNullType<ListType<NonNullType<MetadataEntryType>>>>()
.Resolve(
ctx => ctx.Parent<Metadata>()
.Select(e => new MetadataEntry(e.Key, e.Value.ToString()!)));

descriptor
.Field("value")
.Argument("key", a => a.Type<NonNullType<StringType>>())
.Type<StringType>()
.Resolve(
ctx => ctx.Parent<Metadata>()
.TryGetValue(ctx.ArgumentValue<string>("key"), out var value)
? value?.ToString()
: null);
}
}

public sealed record MetadataEntry(string Key, string Value);

public sealed class MetadataEntryType : ObjectType<MetadataEntry>
{
protected override void Configure(IObjectTypeDescriptor<MetadataEntry> descriptor)
{
descriptor.BindFieldsExplicitly();
descriptor.Field(t => t.Key);
descriptor.Field(t => t.Value);
}
}
}
Loading