Skip to content

Commit

Permalink
Fixed non-null int issue (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Nov 25, 2018
1 parent 7fd1925 commit a084c6e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
34 changes: 34 additions & 0 deletions src/Types.Tests/Types/ObjectTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ public void IntializeExplicitFieldWithImplicitResolver()
Assert.NotNull(fooType.Fields.First().Resolver);
}

[Fact]
public void IntArgumentIsInferedAsNonNullType()
{
// arrange
var errors = new List<SchemaError>();
var schemaContext = new SchemaContext();
var intType = new IntType();
schemaContext.Types.RegisterType(intType);

// act
var fooType = new ObjectType<QueryWithIntArg>();

// assert
var initializationContext = new TypeInitializationContext(
schemaContext, a => errors.Add(a), fooType, false);
((INeedsInitialization)fooType)
.RegisterDependencies(initializationContext);
schemaContext.CompleteTypes();

Assert.Empty(errors);

IType argumentType = fooType.Fields["bar"]
.Arguments.First().Type;

Assert.NotNull(argumentType);
Assert.True(argumentType.IsNonNullType());
Assert.Equal(intType, argumentType.NamedType());
}

[Fact]
public void IntializeImpicitFieldWithImplicitResolver()
{
Expand Down Expand Up @@ -478,6 +507,11 @@ public class FooResolver
public string GetBar(string foo) => "hello foo";
}

public class QueryWithIntArg
{
public string GetBar(int foo) => "hello foo";
}

public class Bar
{
[GraphQLNonNullType]
Expand Down
11 changes: 6 additions & 5 deletions src/Types/Configuration/TypeRegistry.GetType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ private bool TryGetTypeFromClrType<T>(
TypeContext context,
out T type)
{
if (TryGetTypeFromClrType(
DotNetTypeInfoFactory.Unwrap(clrType),
context,
t => t,
out type))
Type unwrappedClrType = DotNetTypeInfoFactory.Unwrap(clrType);

if (!unwrappedClrType.IsValueType
&& TryGetTypeFromClrType(
unwrappedClrType, context,
t => t, out type))
{
return true;
}
Expand Down

0 comments on commit a084c6e

Please sign in to comment.