【发布时间】:2021-05-19 18:50:19
【问题描述】:
下午好,
我不知道如何让 GraphQL 类型对我的泛型计划感到满意。我正在尝试为我的所有查询和突变定义创建一个响应包装器。
使用 PaginationType 和我的服务返回 Pagination 模型的查询定义一切正常,一切都很好。我添加了 ResponseType 包装器,现在我得到了冲突???
类型“ABC.GraphQL.Framework.DTO.ResponseType
1[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