From df5c6f7cbc91c7131dbf19dd606f1daf7c5e6cdf Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Fri, 27 Feb 2026 22:49:59 +0000 Subject: [PATCH] Fix #8756 parse enum strings in reference resolver arguments --- .../Resolvers/ArgumentParser.cs | 21 ++++++- .../Issue8756ReproTests.cs | 63 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/Issue8756ReproTests.cs diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Resolvers/ArgumentParser.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Resolvers/ArgumentParser.cs index c27ab000007..15535661895 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Resolvers/ArgumentParser.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Resolvers/ArgumentParser.cs @@ -132,7 +132,26 @@ private static bool TryGetValue( case SyntaxKind.IntValue: case SyntaxKind.FloatValue: case SyntaxKind.BooleanValue: - if (type.NamedType() is not ScalarType scalarType) + var namedType = type.NamedType(); + + if (namedType is EnumType stringEnumType + && valueNode is StringValueNode stringValue + && stringEnumType.TryGetRuntimeValue(stringValue.Value, out var enumValue)) + { + if (enumValue is T castedEnum) + { + value = castedEnum; + return true; + } + + if (DefaultTypeConverter.Default.TryConvert(typeof(T), enumValue, out var convertedEnum)) + { + value = (T)convertedEnum; + return true; + } + } + + if (namedType is not ScalarType scalarType) { break; } diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/Issue8756ReproTests.cs b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/Issue8756ReproTests.cs new file mode 100644 index 00000000000..88698e4d7ab --- /dev/null +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/Issue8756ReproTests.cs @@ -0,0 +1,63 @@ +using HotChocolate.ApolloFederation.Resolvers; +using HotChocolate.ApolloFederation.Types; +using HotChocolate.Execution; +using HotChocolate.Language; +using Microsoft.Extensions.DependencyInjection; +using static HotChocolate.ApolloFederation.TestHelper; + +namespace HotChocolate.ApolloFederation; + +public class Issue8756ReproTests +{ + [Fact] + public async Task Enum_Value_Is_Parsed_In_Reference_Resolver_When_Representation_Uses_String() + { + var schema = await new ServiceCollection() + .AddGraphQL() + .AddApolloFederation() + .AddQueryType() + .BuildSchemaAsync(); + + var context = CreateResolverContext(schema); + + var representations = new List + { + new( + nameof(Issue8756Entity), + new ObjectValueNode( + new ObjectFieldNode("id", "1"), + new ObjectFieldNode("enumValue", "B"))) + }; + + var result = await EntitiesResolver.ResolveAsync(schema, representations, context); + + var entity = Assert.IsType(result[0]); + Assert.Equal(Issue8756Enum.B, entity.EnumValue); + } + + public class Issue8756Query + { + public Issue8756Entity Issue8756Entity { get; set; } = null!; + } + + [ReferenceResolver(EntityResolver = nameof(Resolve))] + public class Issue8756Entity + { + public string Id { get; set; } = null!; + + public Issue8756Enum EnumValue { get; set; } + + public static Issue8756Entity Resolve(string id, Issue8756Enum enumValue) + => new() + { + Id = id, + EnumValue = enumValue + }; + } + + public enum Issue8756Enum + { + A, + B + } +}