【发布时间】:2019-06-17 15:56:09
【问题描述】:
不能在带有列表标量类型的 graphql Playground 中使用 set。
我已经创建了我的 Prisma datamodel.graphql 并部署了它。我的运动类型中的一个字段是运动列表。我使用列表标量类型来定义这个字段,并在我的 mutation.js 文件中编写了随附的突变。当我尝试在我的 graphql Playground 中添加一个新练习时,我收到了这个错误。
{
"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 并通过手动创建新节点将字符串添加到数组中。
我不确定为什么我不能在我的突变中添加字符串列表。 =
【问题讨论】:
-
嗨,你能分享你生成的 schema.graphql 中
ExerciseCreatemovementInput的部分吗? -
输入ExerciseCreatemovementInput { set: [String!] }}
标签: javascript graphql prisma-graphql