.NET GraphQL类型:无法将ABCModel有效强制为GraphQL类型

.NET GraphQL类型:无法将ABCModel有效强制为GraphQL类型,graphql,Graphql,早上好 我遇到了这个错误,无法找到/理解我在谷歌和星球大战的例子中看到的东西。这是我的设置。我想你不需要看模型,但如果是这样,我可以发布 public class IType : ObjectGraphType<IModel> { public IType() { Field(x => x.iD); Field(x => x.fullName); Field(x => x.email);

早上好

我遇到了这个错误,无法找到/理解我在谷歌和星球大战的例子中看到的东西。这是我的设置。我想你不需要看模型,但如果是这样,我可以发布

public class IType : ObjectGraphType<IModel>
{
    public IType()
    {
        Field(x => x.iD);
        Field(x => x.fullName);
        Field(x => x.email);            
    }
}

public class PType : ObjectGraphType<PModel>
{
    public PType()
    {
        Field(x => x.PID);
        Field(x => x.PValue);
        Field<ListGraphType<SType>>("SKS");          
    }
}

public class SType : ObjectGraphType<SModel>
{
    public SType()
    {
        Field(x => x.SID);
        Field(x => x.Name);   
    }
}
public类IType:ObjectGraphType
{
公共IType()
{
字段(x=>x.iD);
字段(x=>x.fullName);
字段(x=>x.email);
}
}
公共类PType:ObjectGraphType
{
公共PType()
{
字段(x=>x.PID);
字段(x=>x.PValue);
字段(“SKS”);
}
}
公共类SType:ObjectGraphType
{
公共SType()
{
字段(x=>x.SID);
字段(x=>x.Name);
}
}
现在,我创建了一个模型和一个类型,它将上述所有内容组合成一个复杂的对象

public class IPModel
{
    public string iD {get;set;}
    public string fullName{get;set;}
    public string email{get;set;}
    public PModel PWS{get;set;}
}

public class PModel
{
    public int id {get;set;}
    public List<SModel> SKS{get;set;}=new List<SModel>();
}


public class IPType : ObjectGraphType<IPModel>
{
    public IPType()
    {
        Field(x => x.iD);
        Field(x => x.fullName);
        Field(x => x.email);
        Field<PModel>(x => x.PWS);   //Error occurs resolving this type
    }
}
公共类IPModel
{
公共字符串iD{get;set;}
公共字符串全名{get;set;}
公共字符串电子邮件{get;set;}
公共PModel PWS{get;set;}
}
公共类PModel
{
公共int id{get;set;}
公共列表SKS{get;set;}=new List();
}
公共类IPType:ObjectGraphType
{
公共IPType()
{
字段(x=>x.iD);
字段(x=>x.fullName);
字段(x=>x.email);
字段(x=>x.PWS);//解析此类型时出错
}
}
我的错误发生在上面评论的行上

最内层异常System.ArgumentOutOfRangeException:无法将类型:PModel有效强制为GraphQL类型

现在我确信这不是一个bug,而是我缺乏知识/理解,因此如果您能发布文档/示例的链接以及关于我做错了什么的说明,我将不胜感激

(此处交叉张贴:)

免责声明:这是可行的,但不确定为什么以及它是否是正确的解决方案

出于某种原因,任何包含列表的模型/类型似乎都无法通过lambda解析

.NET GraphQL程序集中的字段()具有以下签名

#region Assembly GraphQL, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null
// GraphQL.dll
#endregion

public FieldType Field(Type type, string name, string description = null, QueryArguments arguments = null, Func<ResolveFieldContext<TSourceType>, object> resolve = null, string deprecationReason = null);
#区域组装图ql,版本=2.4.0.0,区域性=中立,PublicKeyToken=null
//GraphQL.dll
#端区
public FieldType字段(类型类型、字符串名称、字符串描述=null、QueryArguments参数=null、Func resolve=null、字符串弃用原因=null);
现在,这些参数是从lamda表达式中解析出来的,但当涉及列表/ListGraphType时,必须显式指定参数

注意:PModel不是一个列表,但它包含一个列表

所以我把它改成:

public class IPType : ObjectGraphType<IPModel>
{
   public IPType()
   {
     Field(x => x.iD);
     Field(x => x.fullName);
     Field(x => x.email);
     Field<PModel>("PWS"); //NOTE:replaced lamda above with string value for name
   }
}
公共类IPType:ObjectGraphType
{
公共IPType()
{
字段(x=>x.iD);
字段(x=>x.fullName);
字段(x=>x.email);
字段(“PWS”);//注意:将上面的lamda替换为名称的字符串值
}
}
我已经交叉发布到,并在那里得到了我更喜欢的解决方案。 信贷:博格丹西

可以这样尝试:Field(x=>x.PWS,null:true,type:typeof(PType))

免责声明:这是可行的,但不确定为什么以及它是否是正确的解决方案

出于某种原因,任何包含列表的模型/类型似乎都无法通过lambda解析

.NET GraphQL程序集中的字段()具有以下签名

#region Assembly GraphQL, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null
// GraphQL.dll
#endregion

public FieldType Field(Type type, string name, string description = null, QueryArguments arguments = null, Func<ResolveFieldContext<TSourceType>, object> resolve = null, string deprecationReason = null);
#区域组装图ql,版本=2.4.0.0,区域性=中立,PublicKeyToken=null
//GraphQL.dll
#端区
public FieldType字段(类型类型、字符串名称、字符串描述=null、QueryArguments参数=null、Func resolve=null、字符串弃用原因=null);
现在,这些参数是从lamda表达式中解析出来的,但当涉及列表/ListGraphType时,必须显式指定参数

注意:PModel不是一个列表,但它包含一个列表

所以我把它改成:

public class IPType : ObjectGraphType<IPModel>
{
   public IPType()
   {
     Field(x => x.iD);
     Field(x => x.fullName);
     Field(x => x.email);
     Field<PModel>("PWS"); //NOTE:replaced lamda above with string value for name
   }
}
公共类IPType:ObjectGraphType
{
公共IPType()
{
字段(x=>x.iD);
字段(x=>x.fullName);
字段(x=>x.email);
字段(“PWS”);//注意:将上面的lamda替换为名称的字符串值
}
}
我已经交叉发布到,并在那里得到了我更喜欢的解决方案。 信贷:博格丹西

可以这样尝试:Field(x=>x.PWS,null:true,type:typeof(PType))