Skip to content

Commit

Permalink
Fixed issue where the backing type was rejected during deserialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jan 21, 2020
1 parent 23537d3 commit 2bd2f41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,31 @@ public void CoerceInputObjectWithEnumInDictionaryGraph()
Assert.Equal(BarEnum.B, bar.F.B);
}

[Fact]
public void Backing_Type_Can_Be_Used_As_Variable()
{
// arrange
Schema schema = CreateSchema();
OperationDefinitionNode operation = CreateQuery(
"query test($test: BarInput!) { a }");

var variableValues = new Dictionary<string, object>
{
{ "test", new Bar { F = new Foo { B = BarEnum.A } } }
};

var resolver = new VariableValueBuilder(schema, operation);

// act
VariableValueCollection coercedVariableValues =
resolver.CreateValues(variableValues);

// assert
Bar bar = coercedVariableValues.GetVariable<Bar>("test");
Assert.NotNull(bar.F);
Assert.Equal(BarEnum.A, bar.F.B);
}

[Fact]
public void CoerceInputObjectWithEnumAsEnumValueNode()
{
Expand Down
12 changes: 12 additions & 0 deletions src/Core/Types/Types/InputObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public object Deserialize(object serialized)
return _deserialize(dict);
}

if (ClrType != typeof(object) && ClrType.IsInstanceOfType(serialized))
{
return serialized;
}

throw new InputObjectSerializationException(
"The specified value is not a serialized input object.");
}
Expand All @@ -163,6 +168,13 @@ public virtual bool TryDeserialize(object serialized, out object value)
return true;
}

if (ClrType != typeof(object) && ClrType.IsInstanceOfType(serialized))
{
value = serialized;
return true;
}


value = null;
return false;
}
Expand Down

0 comments on commit 2bd2f41

Please sign in to comment.