javascript GraphQLError:类型\“StatusInput\”应为对象

polhcujo  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(94)

我可以在Apollo Sandbox中创建一个项目-下面是来自Apollo Sandbox的项目副本

{"data": {"createProject": {"_id": "65952c08576a8d317dc4df47", "description": "front end", "name": "new react", status": [{"code": "a", "launch": "c", "content": "b", "planning": "d","qa": "f", "start": "g", "ux": "h" }]}}

字符串
然而,我在客户端添加了如下突变

mutation createProject($name: String! $description: String! $status: [StatusInput]!) {    createProject(name: $name, description: $description, status: $status) { _id name description status {start planning ux content code qa launch }}}


下面是提交处理程序的useQuery代码

const handleSubmit = async (event) => {
  event.preventDefault();

  try {
    const mutationRes = await createProject({
      variables: {
        name: formState.name,
        description: formState.description,
        status: formState.status,
      },
    });

    console.log(mutationRes);
  } catch (err) {
    console.log(err);
  }
};


我能够看到名称,描述和状态的网络选项卡中的响应,但我得到400状态代码,说明GraphQLError: Expected type "StatusInput" to be an object."
服务器端类型定义:输入

input StatusInput { start: String! planning: String! ux: String! content: String! code: String! qa: String! launch: String! project: ID! }


和变异

createProject( name: String! description: String! status: [StatusInput]! ): Project

chhkpiq4

chhkpiq41#

我改变了模式

status: {
    type: String,
    enum: ["start", "planning", "ux", "content", "code", "qa", "launch"],
  },

字符串
类型定义

enum Status {
start
planning
ux
content
cde
qa
launch


}

type Project {
_id: ID!
name: String!
description: String!
status: Status!
}


与枚举我能够分配项目状态,并解决了问题-任何更多的信息,请随时与我联系

相关问题