Reputation: 93
Cannot use set in graphql playground with list scalar type.
I have created my Prisma datamodel.graphql and deployed it. One of the fields in my Exercise type is a list of movements. I used the list scalar type to define this field, and wrote the accompanying mutation in my mutation.js file. When I try to add a new exercise in my graphql playground I get this error.
{
"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"
]
}
]
}
Here is the mutation i wrote in graphql playground.
mutation {
createExercise(
name: "split squat 3"
movement: ["push", "pull"]
liked: false
) {
id
name
}
}
Here is the datamodel.graphql file.
type User {
id: ID! @unique
name: String!
}
# model for exercises
type Exercise {
id: ID! @unique
name: String!
movement: [String!]!
liked: Boolean
video: String
}
When I write the mutation without any strings and just an empty array like this,
mutation {
createExercise(
name: "split squat 3"
movement: []
liked: false
) {
id
name
}
}
everything works just fine and the exercise is added as a new node.
When I try to write the mutation with set like this,
mutation {
createExercise(
name: "split squat 3"
movement: {set: ["push","pull"]}
liked: false
) {
id
name
}
}
I get an error as well.
I can log into prisma.io and add the strings to the array by manually creating a new node.
Im not sure why I cannot add a list of strings in my mutation. =
Upvotes: 5
Views: 1684
Reputation: 2129
You have to create a separate input just like in the prisma schema.
input ExcerciseCreatemovementInput{
set: [String!]
}
Upvotes: 2