Skip to content

Commit

Permalink
Use structs with non-default constructors as input types w/o configur…
Browse files Browse the repository at this point in the history
…ing (#5844)
  • Loading branch information
atykhyy authored May 1, 2023
1 parent e2274be commit ce20cb7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class InputObjectConstructorResolver

if (AllPropertiesCanWrite(fields))
{
if (constructors.Length == 0)
if (constructors.Length == 0 || type.IsValueType)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public void TypeDiscovery_Should_InferStructs()
.MatchSnapshot();
}

[Fact]
public void InferInputStructsWithNonDefaultCtor()
{
SchemaBuilder.New()
.AddQueryType<QueryTypeWithInputStruct>()
.Create()
.Print()
.MatchSnapshot();
}

public class QueryWithDateTime
{
public DateTimeOffset DateTimeOffset(DateTimeOffset time) => time;
Expand Down Expand Up @@ -109,4 +119,17 @@ public class QueryTypeWithStruct

public DateTime ScalarDateTime { get; set; }
}

public struct InputStructWithCtor
{
public InputStructWithCtor(System.Collections.Generic.IEnumerable<int> values) =>
Values = System.Collections.Immutable.ImmutableArray.CreateRange(values);

public System.Collections.Immutable.ImmutableArray<int> Values { get; set; }
}

public class QueryTypeWithInputStruct
{
public int Foo(InputStructWithCtor arg) => default;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema {
query: QueryTypeWithInputStruct
}

type QueryTypeWithInputStruct {
foo(arg: InputStructWithCtorInput!): Int!
}

input InputStructWithCtorInput {
values: [Int!]!
}

0 comments on commit ce20cb7

Please sign in to comment.