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
6 changes: 0 additions & 6 deletions src/HotChocolate/Core/src/Types/Internal/TypeDiscoveryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ private static bool IsComplexTypeInternal(
IsByRefLike: false
};

if (isComplexValueType && unresolvedType.IsGeneric)
{
var typeDefinition = unresolvedType.Definition;
return typeDefinition == typeof(KeyValuePair<,>);
}

return isComplexClass || isComplexValueType;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable disable

using System.Numerics;
using HotChocolate.Types;
using HotChocolate.Types.Descriptors;
using HotChocolate.Utilities;
Expand Down Expand Up @@ -253,6 +254,33 @@ public void Cannot_Infer_Multiple_Input_Type()
});
}

[Fact]
public void Can_Infer_Generic_Record_Struct_Input_Type()
{
// arrange
var context = DescriptorContext.Create();
var typeRegistry = new TypeRegistry(context.TypeInterceptor);
var typeLookup = new TypeLookup(context.TypeInspector, typeRegistry);

var typeDiscoverer = new TypeDiscoverer(
context,
typeRegistry,
typeLookup,
new HashSet<TypeReference>
{
_typeInspector.GetTypeRef(
typeof(QueryWithGenericRecordStructInput),
TypeContext.Output)
},
new AggregateTypeInterceptor());

// act
var errors = typeDiscoverer.DiscoverTypes();

// assert
Assert.Empty(errors);
}

public class FooType
: ObjectType<Foo>
{
Expand Down Expand Up @@ -284,5 +312,15 @@ public class QueryWithInferError2
public string Foo(IMyArg o) => throw new NotImplementedException();
}

public class QueryWithGenericRecordStructInput
{
public string Foo(RangeSpec<int> range) => throw new NotImplementedException();
}

public readonly record struct RangeSpec<T>(
T? Min,
T? Max)
where T : struct, IComparable<T>, IComparisonOperators<T, T, bool>;

public interface IMyArg;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Numerics;
using HotChocolate.Types;

namespace HotChocolate.Configuration;
Expand Down Expand Up @@ -54,6 +55,16 @@ public void InferInputTypeWithComputedProperty()
.MatchSnapshot();
}

[Fact]
public void InferGenericRecordStructInput()
{
SchemaBuilder.New()
.AddQueryType<QueryTypeWithGenericRecordStructInput>()
.Create()
.ToString()
.MatchSnapshot();
}

[Fact]
public void Custom_LocalDate_Should_Throw_SchemaException_When_Not_Bound()
{
Expand Down Expand Up @@ -167,6 +178,16 @@ public class QueryTypeWithComputedProperty
public int Foo(InputTypeWithReadOnlyProperties arg) => arg.Property1;
}

public class QueryTypeWithGenericRecordStructInput
{
public string Foo(RangeSpec<int> range) => "bar";
}

public readonly record struct RangeSpec<T>(
T? Min,
T? Max)
where T : struct, IComparable<T>, IComparisonOperators<T, T, bool>;

public class QueryTypeWithCustomLocalDate
{
public LocalDate Foo() => new();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
schema {
query: QueryTypeWithGenericRecordStructInput
}

type QueryTypeWithGenericRecordStructInput {
foo(range: RangeSpecOfInt32Input!): String!
}

input RangeSpecOfInt32Input {
min: Int
max: Int
}
Loading