diff --git a/src/HotChocolate/Core/src/Types/Utilities/Serialization/InputObjectConstructorResolver.cs b/src/HotChocolate/Core/src/Types/Utilities/Serialization/InputObjectConstructorResolver.cs index 57f83b4ce89..dfe70b0b304 100644 --- a/src/HotChocolate/Core/src/Types/Utilities/Serialization/InputObjectConstructorResolver.cs +++ b/src/HotChocolate/Core/src/Types/Utilities/Serialization/InputObjectConstructorResolver.cs @@ -24,7 +24,7 @@ internal static class InputObjectConstructorResolver if (AllPropertiesCanWrite(fields)) { - if (constructors.Length == 0) + if (constructors.Length == 0 || type.IsValueType) { return null; } diff --git a/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs b/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs index c65e6d45884..47c7054e6a2 100644 --- a/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs +++ b/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs @@ -37,6 +37,16 @@ public void TypeDiscovery_Should_InferStructs() .MatchSnapshot(); } + [Fact] + public void InferInputStructsWithNonDefaultCtor() + { + SchemaBuilder.New() + .AddQueryType() + .Create() + .Print() + .MatchSnapshot(); + } + public class QueryWithDateTime { public DateTimeOffset DateTimeOffset(DateTimeOffset time) => time; @@ -109,4 +119,17 @@ public class QueryTypeWithStruct public DateTime ScalarDateTime { get; set; } } + + public struct InputStructWithCtor + { + public InputStructWithCtor(System.Collections.Generic.IEnumerable values) => + Values = System.Collections.Immutable.ImmutableArray.CreateRange(values); + + public System.Collections.Immutable.ImmutableArray Values { get; set; } + } + + public class QueryTypeWithInputStruct + { + public int Foo(InputStructWithCtor arg) => default; + } } diff --git a/src/HotChocolate/Core/test/Types.Tests/Configuration/__snapshots__/TypeDiscoveryTests.InferInputStructsWithNonDefaultCtor.snap b/src/HotChocolate/Core/test/Types.Tests/Configuration/__snapshots__/TypeDiscoveryTests.InferInputStructsWithNonDefaultCtor.snap new file mode 100644 index 00000000000..4729f8f2abf --- /dev/null +++ b/src/HotChocolate/Core/test/Types.Tests/Configuration/__snapshots__/TypeDiscoveryTests.InferInputStructsWithNonDefaultCtor.snap @@ -0,0 +1,11 @@ +schema { + query: QueryTypeWithInputStruct +} + +type QueryTypeWithInputStruct { + foo(arg: InputStructWithCtorInput!): Int! +} + +input InputStructWithCtorInput { + values: [Int!]! +}