I'm new to GraphQL, I'm making a small website which is for managing students and there classes.
In my application, I have a generic class:
public class RangeModel<TFrom, TTo>
{
#region Propertes
public TFrom From { get; set; }
public TTo To { get; set; }
#endregion
}
This class is for defining a range with generic data type. Range can be:
RangeModel<double?, double?>
RangeModel<int?, int?>
... and so on.
I have tried making a RangeModelType class which inherits ObjectGraphType :
public class RangeModelType<TFrom, TTo>: InputObjectGraphType<RangeModel<TFrom, TTo>>
{
public RangeModelType()
{
Field(x => x.From).Description("Minimum range");
Field(x => x.To).Description("Maximum range");
}
}
And defined my query like below:
var studentsQueryArguments = new QueryArguments();
studentsQueryArguments.Add(new QueryArgument<ListGraphType<IntGraphType>> { Name = "ids", Description = "Student indexes." });
studentsQueryArguments.Add(new QueryArgument<ObjectGraphType<RangeModelType<double?, double?>>>{Name = "age", Description = "Age range of student."});
Field<ListGraphType<StudentType>>(
"students",
arguments: studentsQueryArguments,
resolve: context =>
{
// Resolve data...
return results;
});
}
When I ran my app and did the query. One exception was thrown back which said:
Unable to cast object of type GraphQL.Types.ObjectGraphType1[GraphQlStudy.Models.GraphQL.Types.RangeModelType2[System.Nullable1[System.Double],System.Nullable1[System.Double]]]' to type 'GraphQL.Types.ScalarGraphType'.
I have been searching for tutorials that use GraphQL and generic class, but nothing mentions about using this kind of Generic class.
Can anyone help me ?
Thanks,