javascript - 无法用字符串数组编写突变
问题描述
不能在带有列表标量类型的 graphql 游乐场中使用 set。
我已经创建了我的 Prisma datamodel.graphql 并部署了它。我的运动类型中的一个字段是运动列表。我使用列表标量类型来定义这个字段,并在我的 mutation.js 文件中编写了随附的突变。当我尝试在我的 graphql 操场上添加一个新练习时,我收到了这个错误。
{
"data": null,
"errors": [
{
"message": "Variable \"$_v0_data\" got invalid value {\"name\":\"split squat 3\",\"movement\":[\"push\",\"pull\"],\"liked\":false}; Field \"0\" is not defined by type ExerciseCreatemovementInput at value.movement.\nVariable \"$_v0_data\" got invalid value {\"name\":\"split squat 3\",\"movement\":[\"push\",\"pull\"],\"liked\":false}; Field \"1\" is not defined by type ExerciseCreatemovementInput at value.movement.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createExercise"
]
}
]
}
这是我在 graphql 操场上写的突变。
mutation {
createExercise(
name: "split squat 3"
movement: ["push", "pull"]
liked: false
) {
id
name
}
}
这是 datamodel.graphql 文件。
type User {
id: ID! @unique
name: String!
}
# model for exercises
type Exercise {
id: ID! @unique
name: String!
movement: [String!]!
liked: Boolean
video: String
}
当我编写没有任何字符串的突变时,只有一个像这样的空数组,
mutation {
createExercise(
name: "split squat 3"
movement: []
liked: false
) {
id
name
}
}
一切正常,练习被添加为一个新节点。
当我尝试用这样的集合编写突变时,
mutation {
createExercise(
name: "split squat 3"
movement: {set: ["push","pull"]}
liked: false
) {
id
name
}
}
我也得到一个错误。
我可以登录 prisma.io 并通过手动创建新节点将字符串添加到数组中。
我不确定为什么我不能在我的突变中添加字符串列表。=
解决方案
您必须像在 prisma 模式中一样创建单独的输入。
input ExcerciseCreatemovementInput{
set: [String!]
}
推荐阅读
- javascript - 像在 Kotlin 中一样将 BigNumber 转换为 Int
- xcode - 在 azure 管道和本地机器上运行相同的 xcodebuild 命令最终会产生一个小的差异 - 并且不可运行
- google-cloud-firestore - Firestore 全局安全规则
- python - 如何在 django 模型中将 slug 从一个类继承到另一个类
- github - 无法打开与您的身份验证代理的连接,ubuntu 上的 ssh
- django - Django Rest Framework:在 URL 中使用带有主键的 create
- mule - 在将响应属性发送到客户端应用程序之前,如何在响应属性中注入自定义标头?
- javascript - 正则表达式严格测试
- node.js - 如何使用nodejs中的工作线程在mongoDB中插入新数据
- javascript - 身体上的 mousemove 停止 childs 上的 mouseenter