5

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. =

2
  • Hi, could you share the part in your generated schema.graphql where there is ExerciseCreatemovementInput ? Commented Jan 24, 2019 at 10:11
  • input ExerciseCreatemovementInput { set: [String!] }} Commented Jan 24, 2019 at 17:44

2 Answers 2

2

You have to create a separate input just like in the prisma schema.

input ExcerciseCreatemovementInput{
  set: [String!]
}
Sign up to request clarification or add additional context in comments.

Comments

0

movement: {set: ["push","pull"]} is working for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.