【问题标题】:Trigger a GraphQL mutation not using the Mutation component不使用 Mutation 组件触发 GraphQL 突变
【发布时间】:2019-11-23 16:35:30
【问题描述】:

我正在尝试向使用 Apollo 的 GraphQL 服务器发送突变查询。

但是,我只看到实现此目的的唯一方法是使用 Mutation 组件。 https://www.apollographql.com/docs/react/essentials/mutations/#the-mutation-component

有没有一种简单的方法可以发送突变做这样的事情?

从'graphql-tag'导入gql;

client.query({
  query: gql`
    query TodoApp {
      todos {
        id
        text
        completed
      }
    }
  `,
})
  .then(data => console.log(data))
  .catch(error => console.error(error));

【问题讨论】:

    标签: graphql apollo apollo-client


    【解决方案1】:

    您不需要突变组件来触发突变。

    您可以在 gql 查询对象中传递突变,例如:

    client.query({
      query: gql`
        mutation MyMutation {
          doSomthing {
            id
            returnedValue1
          }
        }
      `,
    })
    .then(data => console.log(data))
    .catch(error => console.error(error));
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 2017-08-31
      • 1970-01-01
      • 1970-01-01
      • 2018-06-20
      • 2018-10-20
      • 2022-01-05
      • 2019-04-07
      • 2019-01-08
      相关资源
      最近更新 更多