【问题标题】:Apollo GraphQL: Multiple Queries in One Component?Apollo GraphQL:一个组件中的多个查询?
【发布时间】:2017-03-12 11:50:19
【问题描述】:

我有一个组件需要查询两个完全独立的表。在这种情况下,模式、查询和解析器需要是什么样的?我用谷歌搜索但还没有找到例子。提前感谢您提供任何信息。

更新: 在 Slack 上,我看到可能有一种方法可以为此目的使用 compose,例如:

export default compose(
  graphql(query1, 
  ....),
  graphql(query2, 
  ....),
  graphql(query3, 
  ....),
  withApollo
)(PrintListEditPage)

有没有办法像这样拥有多个声明:

const withMutations = graphql(updateName, {
  props({ mutate }) {
    return {
      updatePrintListName({ printListId, name }) {
        return mutate({
          variables: { printListId, name },
        });
      },
    };
  },
});

...在调用export default compose之前出现?

【问题讨论】:

    标签: graphql apollo apollo-server


    【解决方案1】:

    graphql 函数采用可选的第二个参数,允许您为传递的属性名称设置别名。如果您有多个突变,您可以根据需要使用name 属性重命名mutate

    import { graphql, compose } from 'react-apollo'
    
    export default compose(
      graphql(mutation1, { name: 'createSomething' }),
      graphql(mutation2, { name: 'deleteSomething' }),
    )(Component)
    

    更多详情请见the complete API

    【讨论】:

    • 这已经过时了。 react-apollo 不再导出 compose
    猜你喜欢
    • 2018-07-09
    • 2021-06-17
    • 2020-08-17
    • 2017-11-10
    • 2021-01-19
    • 2020-10-18
    • 2017-03-07
    • 2018-08-16
    • 2020-02-05
    相关资源
    最近更新 更多