Skip to content

Commit fbff0b8

Browse files
committed
Added hook to allow for F# support. (#8722)
1 parent 0136c1b commit fbff0b8

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/HotChocolate/Core/src/Types/Internal/ExtendedType.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
using System.Collections.Immutable;
12
using System.Reflection;
3+
using HotChocolate.Types;
24

35
#nullable enable
46

57
namespace HotChocolate.Internal;
68

79
internal sealed partial class ExtendedType : IExtendedType
810
{
11+
internal static ImmutableHashSet<Type> NonEssentialWrapperTypes { get; set; } =
12+
[typeof(ValueTask<>), typeof(Task<>), typeof(NativeType<>), typeof(Optional<>)];
13+
914
private ExtendedType(
1015
Type type,
1116
ExtendedTypeKind kind,
@@ -220,4 +225,23 @@ public static ExtendedMethodInfo FromMethod(MethodInfo method, TypeCache cache)
220225

221226
return Members.FromMethod(method, cache);
222227
}
228+
229+
public static void RegisterNonEssentialWrapperTypes(Type type)
230+
{
231+
ArgumentNullException.ThrowIfNull(type);
232+
233+
if (!type.IsGenericTypeDefinition)
234+
{
235+
throw new ArgumentException(
236+
"The type must be a generic type definition.",
237+
nameof(type));
238+
}
239+
240+
if (NonEssentialWrapperTypes.Contains(type))
241+
{
242+
return;
243+
}
244+
245+
NonEssentialWrapperTypes = NonEssentialWrapperTypes.Add(type);
246+
}
223247
}

src/HotChocolate/Core/src/Types/Internal/TypeInfo.RuntimeType.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Diagnostics.CodeAnalysis;
2-
using HotChocolate.Types;
32

43
#nullable enable
54

@@ -92,12 +91,12 @@ private static IExtendedType RemoveNonEssentialParts(IExtendedType type)
9291
short i = 0;
9392
var current = type;
9493

95-
while (IsWrapperType(current) ||
96-
IsTaskType(current) ||
97-
IsOptional(current) ||
98-
IsFieldResult(current))
94+
while (
95+
current is { IsGeneric: true, Definition: { } definition }
96+
&& (ExtendedType.NonEssentialWrapperTypes.Contains(definition)
97+
|| typeof(IFieldResult).IsAssignableFrom(current)))
9998
{
100-
current = type.TypeArguments[0];
99+
current = current.TypeArguments[0];
101100

102101
if (i++ > 64)
103102
{
@@ -108,21 +107,5 @@ private static IExtendedType RemoveNonEssentialParts(IExtendedType type)
108107

109108
return current;
110109
}
111-
112-
private static bool IsWrapperType(IExtendedType type) =>
113-
type.IsGeneric &&
114-
typeof(NativeType<>) == type.Definition;
115-
116-
private static bool IsTaskType(IExtendedType type) =>
117-
type.IsGeneric &&
118-
(typeof(Task<>) == type.Definition ||
119-
typeof(ValueTask<>) == type.Definition);
120-
121-
private static bool IsOptional(IExtendedType type) =>
122-
type.IsGeneric &&
123-
typeof(Optional<>) == type.Definition;
124-
125-
private static bool IsFieldResult(IExtendedType type) =>
126-
type.IsGeneric && typeof(IFieldResult).IsAssignableFrom(type);
127110
}
128111
}

0 commit comments

Comments
 (0)