0

I am trying to validate a GraphQL mutation with variables and I am not clear on how to define variables - the moment I declare a variable in the query it fails validation. I am not sure where the issue is:

Schema

input ItemCreateInput {
  clientMutationId: ID
}

type Mutation {
  itemCreate(input: ItemCreateInput): ItemCreatePayload!
}

Query

mutation {
  itemCreate(
    input: $input
  ) {
    ids
  }
}

Variables

{
 "input": {
    "clientMutationId": 1575680625627
 }
}

This rejects with Variable \"$input\" is not defined.. But I am confused because the validate function does not accept variables as parameter so why is it validating them?

Where is the issue? how can I correctly define and pass variables?

cyberwombat
  • 38,105
  • 35
  • 175
  • 251
  • As the error indicates, the variable you are trying to use is not defined. Variables must be defined as part of the operation definition if they are used inside the operation. – Daniel Rearden Dec 07 '19 at 19:36
  • An thank you. I hadn't really grasped what the docs where saying till I read that post. – cyberwombat Dec 07 '19 at 19:55

0 Answers0