graphql-dotnet: Type comparison appears to be wrong in InputObjectGraphType
InputObjectGraphType is defined as:
public class InputObjectGraphType<TSourceType> : ComplexGraphType<TSourceType>, IInputObjectGraphType
{
public override FieldType AddField(FieldType fieldType)
{
if (fieldType.Type == typeof(ObjectGraphType))
{
throw new ArgumentException("InputObjectGraphType cannot have fields containing a ObjectGraphType.", nameof(fieldType.Type));
}
return base.AddField(fieldType);
}
}
It would appear that this line of code:
if (fieldType.Type == typeof(ObjectGraphType))
should have been written as:
if ((fieldType.Type != null && typeof(ObjectGraphType).IsAssignableFrom(fieldType.Type)) || ((fieldType.ResolvedType as ObjectGraphType) != null))
Is that correct? If so, I can submit a pull request
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 31 (31 by maintainers)
I ran a few other tests against it to be sure, and everything looks good to me!
Have methods like that already, though they target the ResolvedType (in general, in most cases only need to deal with the ResolvedType during execution).
https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/GraphQL/GraphQLExtensions.cs#L30-L42
There is the following:
https://github.com/graphql-dotnet/graphql-dotnet/blob/fe0368f15dcea1dd578e83c521b985798e1a2214/src/GraphQL/GraphQLExtensions.cs#L44-L48
Though it only works with objects that have a
ResolvedType. It could be updated to also check theType, if there is noResolvedType.I would suggest to use the interface
IObjectGraphTypevs. the specific type.