Skip to content

Commit a084c6e

Browse files
authored
Fixed non-null int issue (#362)
1 parent 7fd1925 commit a084c6e

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/Types.Tests/Types/ObjectTypeTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ public void IntializeExplicitFieldWithImplicitResolver()
3131
Assert.NotNull(fooType.Fields.First().Resolver);
3232
}
3333

34+
[Fact]
35+
public void IntArgumentIsInferedAsNonNullType()
36+
{
37+
// arrange
38+
var errors = new List<SchemaError>();
39+
var schemaContext = new SchemaContext();
40+
var intType = new IntType();
41+
schemaContext.Types.RegisterType(intType);
42+
43+
// act
44+
var fooType = new ObjectType<QueryWithIntArg>();
45+
46+
// assert
47+
var initializationContext = new TypeInitializationContext(
48+
schemaContext, a => errors.Add(a), fooType, false);
49+
((INeedsInitialization)fooType)
50+
.RegisterDependencies(initializationContext);
51+
schemaContext.CompleteTypes();
52+
53+
Assert.Empty(errors);
54+
55+
IType argumentType = fooType.Fields["bar"]
56+
.Arguments.First().Type;
57+
58+
Assert.NotNull(argumentType);
59+
Assert.True(argumentType.IsNonNullType());
60+
Assert.Equal(intType, argumentType.NamedType());
61+
}
62+
3463
[Fact]
3564
public void IntializeImpicitFieldWithImplicitResolver()
3665
{
@@ -478,6 +507,11 @@ public class FooResolver
478507
public string GetBar(string foo) => "hello foo";
479508
}
480509

510+
public class QueryWithIntArg
511+
{
512+
public string GetBar(int foo) => "hello foo";
513+
}
514+
481515
public class Bar
482516
{
483517
[GraphQLNonNullType]

src/Types/Configuration/TypeRegistry.GetType.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ private bool TryGetTypeFromClrType<T>(
179179
TypeContext context,
180180
out T type)
181181
{
182-
if (TryGetTypeFromClrType(
183-
DotNetTypeInfoFactory.Unwrap(clrType),
184-
context,
185-
t => t,
186-
out type))
182+
Type unwrappedClrType = DotNetTypeInfoFactory.Unwrap(clrType);
183+
184+
if (!unwrappedClrType.IsValueType
185+
&& TryGetTypeFromClrType(
186+
unwrappedClrType, context,
187+
t => t, out type))
187188
{
188189
return true;
189190
}

0 commit comments

Comments
 (0)