Dan*_*ili 5 javascript graphql prisma-graphql
不能在具有列表标量类型的 graphql 操场中使用 set。
我已经创建了我的 Prisma datamodel.graphql 并部署了它。我的运动类型中的一个字段是运动列表。我使用列表标量类型来定义这个字段,并在我的mutation.js 文件中写入了伴随的mutation。当我尝试在我的 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"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我在 graphql 操场上写的突变。
mutation {
createExercise(
name: "split squat 3"
movement: ["push", "pull"]
liked: false
) {
id
name
}
}
Run Code Online (Sandbox Code Playgroud)
这是 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
}
Run Code Online (Sandbox Code Playgroud)
当我在没有任何字符串的情况下只写一个像这样的空数组时,
mutation {
createExercise(
name: "split squat 3"
movement: []
liked: false
) {
id
name
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,练习被添加为一个新节点。
当我尝试用这样的 set 编写突变时,
mutation {
createExercise(
name: "split squat 3"
movement: {set: ["push","pull"]}
liked: false
) {
id
name
}
}
Run Code Online (Sandbox Code Playgroud)
我也收到错误。
我可以登录到prisma.io 并通过手动创建一个新节点将字符串添加到数组中。
我不知道为什么我不能在我的突变中添加字符串列表。=
您必须创建一个单独的输入,就像在 prisma 模式中一样。
input ExcerciseCreatemovementInput{
set: [String!]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1269 次 |
| 最近记录: |