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

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

我正在尝试以这种格式创建两个单独的突变:

import gql from 'graphql-tag';

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

但是我收到这个错误:

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

构建此结构以使两个突变都可用的正确方法是什么?

您只需输入一次 mutation 并嵌套在(变异)字段中:

import gql from 'graphql-tag';

const MUTATION = gql`
  mutation MyMutation ($item: String, $setAnotherItem: Book) {
    setItem(item: $item) { ...}
    setAnotherItem(setAnotherItem: $setAnotherItem) {...}
  }
`;