【发布时间】:2019-09-18 19:48:45
【问题描述】:
我正在尝试构建一个接受集合的突变。 GraphQL 服务器是用 c# .net core 编写的,使用 GraphQL.Net。
这是我的输入类型;
public class PupilReportInputType : InputObjectGraphType<PupilReport>
{
public PupilReportInputType()
{
Name = "PupilReportInput";
Field(pr => pr.PupilId);
Field(pr => pr.PupilMetricCollections, type: typeof(ListGraphType<PupilMetricCollectionInputType>));
}
}
使用 GraphiQL 我尝试发布以下突变;
mutation getPupilReportText($pupilReport: PupilReportInput!) {
getPupilReportText(pupilReport: $pupilReport)
}
使用以下变量;
{
"pupilReport": {
"pupilId" : 5,
"pupilMetricCollections": {
"pupilMetricCollection" : {
"pupilId" : 5
}
}
}
}
我得到的回应是;
{
"errors": [
{
"message": "Variable '$pupilReport.pupilMetricCollections[0]' is invalid. Unable to parse input as a 'PlayerMetricCollectionInput' type. Did you provide a List or Scalar value accidentally?",
"extensions": {
"code": "INVALID_VALUE"
}
}
]
}
如果PupilReportInputType 删除了PupilMetricCollections 字段并且对变异变量进行了类似调整,则查询的行为与预期一致(不是错误)。同样,如果我修改变量输入和PupilReportInputType,使该字段只是PupilMetricCollectionInputType 而不是ListGraphType<PupilMetricCollectionInputType>,那么我可以让它全部工作。
如何在PupilMetricCollectionInputType 上传递集合?我需要某种 ListGraphInputType 吗?
【问题讨论】:
标签: c# graphql graphql.net