Skip to content

Commit

Permalink
Merge branch 'version_10_0_0_master' into schema_builder_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Dec 15, 2019
2 parents e0b0daf + 9f1e8d7 commit 35ed441
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/Core/Types.Tests/Utilities/DotNetTypeInfoFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,31 @@ public void Rewrite(
Assert.Equal(expectedReducedType, reducedType);
}

[Fact]
public void Create_TypeInfo_From_RewrittenType()
{
// arrange
Type type = typeof(ListType<NonNullType<NativeType<string>>>);
var factory = new DotNetTypeInfoFactory();

// act
bool success = factory.TryCreate(type, out TypeInfo typeInfo);

// assert
Assert.True(success);

Assert.Collection(typeInfo.Components,
t => Assert.Equal(typeof(ListType<NonNullType<NativeType<string>>>), t),
t => Assert.Equal(typeof(NonNullType<NativeType<string>>), t),
t => Assert.Equal(typeof(string), t));

IType schemaType = typeInfo.TypeFactory(new StringType());

Assert.IsType<StringType>(
Assert.IsType<NonNullType>(
Assert.IsType<ListType>(schemaType).ElementType).Type);
}

private class CustomStringList
: CustomStringListBase
{
Expand Down
15 changes: 10 additions & 5 deletions src/Core/Types/Utilities/DotNetTypeInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,24 @@ private static Type RemoveNonEssentialParts(Type type)

private static bool IsTypeStackValid(List<Type> components)
{
if (components.Count == 0)
{
return false;
}

foreach (Type type in components)
{
if (typeof(Task).IsAssignableFrom(type))
{
return false;
}
}

if (typeof(IType).IsAssignableFrom(type)
&& !IsNonNullType(type))
{
return false;
}
if (typeof(IType).IsAssignableFrom(components[components.Count - 1]))
{
return false;
}

return true;
}

Expand Down

0 comments on commit 35ed441

Please sign in to comment.