React-Apollo error: "…only supports a query, subscription, or a mutation per HOC"

I am trying to create two separate mutations in this format:

import gql from 'graphql-tag';

const MUTATION = gql`
  mutation setItem($item:String!) {
    setItem(item:$item)
  },
  mutation setAnotherItem($setAnotherItem:Bool) {
    setAnotherItem(setAnotherItem:$setAnotherItem)
  }
`;

But I am getting this error:

Invariant Violation: react-apollo only supports a query, subscription, or a mutation per HOC. [object Object] had 0 queries, 0 subscriptions and 2 mutations. You can use 'compose' to join multiple operation types to a component

What is the proper way to structure this so that both mutations are usable?

24 thoughts on “React-Apollo error: "…only supports a query, subscription, or a mutation per HOC"”

  1. You need to type just once mutation and nest inside the (mutation) fields:

    import gql from 'graphql-tag';
    
    const MUTATION = gql`
      mutation MyMutation ($item: String, $setAnotherItem: Book) {
        setItem(item: $item) { ...}
        setAnotherItem(setAnotherItem: $setAnotherItem) {...}
      }
    `;
    
    Reply

Leave a Comment