【问题标题】:React-Apollo error: "...only supports a query, subscription, or a mutation per HOC"React-Apollo 错误:“...仅支持每个 HOC 的查询、订阅或突变”
【发布时间】:2021-05-21 02:41:02
【问题描述】:

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

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

什么是构造这个以使两个突变都可用的正确方法?

【问题讨论】:

    标签: javascript graphql apollo react-apollo graphql-mutation


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-02-19
      • 2017-07-16
      • 2019-07-11
      • 2023-04-11
      • 2019-09-18
      • 2020-01-23
      • 2020-11-04
      • 1970-01-01
      • 2017-02-11
      相关资源
      最近更新 更多