我在尝试构建一个接受一个集合的变异。GraphQL服务器使用c# .net内核编写,并使用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吗?
发布于 2019-05-01 06:53:01
我是graphQL新手,因此我认为我所犯的错误是在我的代码中。事实上,我收到的响应信息给了我所需的所有信息;我发送的可变数据确实是错误的。
我寄了这个;
{
"pupilReport": {
"pupilId" : 5,
"pupilMetricCollections": {
"pupilMetricCollection" : {
"pupilId" : 5
}
}
}
}但是,pupilMetricCollections是数组类型;所以我需要使用数组语法。以下工作正常;
{
"pupilReport": {
"pupilId" : 5,
"pupilMetricCollections": [
{
"pupilId" : 1
},
{
"pupilId" : 2
}
]
}
}我最大的收获就是相信GraphQL的错误响应,不要忘记寻找显而易见的东西!
https://stackoverflow.com/questions/55916023
复制相似问题