【问题标题】:GraphQL Generics Unexpected Value Type ErrorGraphQL 泛型意外值类型错误
【发布时间】:2021-05-19 18:50:19
【问题描述】:

下午好,

我不知道如何让 GraphQL 类型对我的泛型计划感到满意。我正在尝试为我的所有查询和突变定义创建一个响应包装器。

使用 PaginationType 和我的服务返回 Pagination 模型的查询定义一切正常,一切都很好。我添加了 ResponseType 包装器,现在我得到了冲突???

类型“ABC.GraphQL.Framework.DTO.ResponseType1[ABC.GraphQL.Framework.Types.Object.PaginationType]\" for \"ResponseType\" but got: ABC.GraphQL.Framework.DTO.Response1[ABC.GraphQL.Framework.DTO.Pagination].”的预期值,

FieldAsync<ResponseType<PaginationType>>(
   "PaginationSearch",
   "Returns paginated groups for specified search terms",
   arguments: new QueryArguments(...),
   resolve: async context => {
          return await Service.GetPagination(...);
          }
);
public class PaginationType : ObjectGraphType<Pagination>
{
   public PaginationType()
   {
      Field(x => x.totalRecords, nullable: true).Description("Total Records");
       ....
   }
}
public class ResponseType<T> : ObjectGraphType<Response<T>>
{
   public ResponseType()
   {
      Name = "ResponseType";
      Field(x => x.success, nullable: true).Description("Operation Success");
      Field(x => x.message, nullable: true).Description("Operation Message");
      Field(x => x.response, nullable: true, typeof(T)).Description("Operation Response");
    }        
}

当然是普通的支持模型

public class Pagination
{
   public int totalRecords { get; set; }
  .....
}

public class Response<T>
{
   public bool success { get; set; }
   public string message { get; set; }
   public T response { get; set; }
}

现在我的服务类返回普通对象,这一直有效,所以不知道为什么现在添加响应包装器会破坏它。

public async Task<Response<Pagination>> GetPagination(...)
{...}

如果我遗漏了什么或需要发布更多内容,我会很乐意这样做。

TIA

【问题讨论】:

    标签: graphql


    【解决方案1】:

    我调试到 GraphQL 库,发现它是设计使然。所以我开始深入研究原因并发现了这一点:

    https://github.com/graphql-dotnet/graphql-dotnet/issues/2279

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2015-12-11
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多