Karl Stefan
Karl Stefan

Reputation: 160

Apollo React GraphQL VariableTypeMismatch error

I've got a mutation that looks like this:

mutation ADD_CATEGORY($id: ID!, $category: ID!) {
  addCategory(id: $id, category: $category)
}

It is passed into my React component as addCategory.

My handleSave function looks like this:

    handleSave = () => {
      const { id, category } = this.state;
      addCategory({ variables: { id, category: category.id } });
    }

id and category.id are a string property on this.state object.

I get the following error:

[GraphQL error]: Message: Validation error of type VariableTypeMismatch: Variable type doesn't match, Location: [object Object], Path: null

Looking at the API from GraphiQL I see that the updateCategory mutation has the following arguments:

id: ID!
category: [ID!]!

What am I missing here?

Upvotes: 0

Views: 3340

Answers (1)

prc
prc

Reputation: 41

Please make sure addCategory schema accepting String type for id & category. From your API output looks like category is Array type.

Upvotes: 1

Related Questions