.net - 在 Graphql 我需要显示列表
问题描述
我想返回数据列表,传递 id。低于错误Graphql
{ "errorMessage": [ "System.InvalidOperationException: "System.Collections.Generic.List 1[GraphQLAPI.Domain.PatientInfo]\" value of type \"System.Collections.Generic.List
1[GraphQLAPI.Domain.PatientInfo]" 不允许用于 "PatientType"。要么更改 "PatientType" 的 IsTypeOf 方法以接受此值,要么返回来自解析器的另一个值。\r\n 在 GraphQL.Execution.ExecutionStrategy.ValidateNodeResult(ExecutionContext context, ExecutionNode node) in / /src/GraphQL/Execution/ExecutionStrategy.cs:line 404\r\n at GraphQL.Execution.ExecutionStrategy .CompleteNode(ExecutionContext context, ExecutionNode node) in //src/GraphQL/Execution/ExecutionStrategy.cs:line 316" ] }
公共类 PatientQuery: ObjectGraphType { PatientInfoService infoService = new PatientInfoService();
public PatientQuery()
{
Field<PatientDetailsType>(
name: "patient",
arguments: new QueryArguments(new QueryArgument<IntGraphType> { Name = "patientid" }),
resolve: context =>
{
var id = context.GetArgument<int>("patientid");
return infoService.GetPatientById(id);
}
);
}
}
infoservice.GetPatientBYid(id) 返回列表。
解决方案
假设 infoService.GetPatientById() 返回一个列表,则以下更改将反映在解析器中。
这一行:
...
Field<PatientDetailsType>(
...
至:
...
Field<ListGraphType<PatientDetailsType>>(
...
推荐阅读
- scala - Scala ReactiveMongo 示例。遗漏的操作或隐含
- python - Python CSV如何删除第一行数据?
- php - 如何向 request()->all() 添加变量?(Laravel 6.0)
- javascript - v-for 渲染组件和
,如何只为一个组件实例更改它 - c# - 如何使用 Xamarin 在 iOS 13 中获取设备令牌?
- mongodb - 您如何对聚合管道的输出进行分页?
- php - 如何使用 PHP SDK v2 从 aws s3 headObject 读取结果?
- angular - 为什么我得到 TypeError system.config is not a function?
- react-native - React Native 为什么每次点击 textInput 时我的键盘都会立即消失?
- azure - 如何使用 terraform 在虚拟机中启用 Azure Monitor?