Apollo GraphQL:一个组件中的多个查询?

Vik*_*ikR 7 apollo graphql apollo-server

我有一个组件需要查询两个完全独立的表.在这种情况下,架构,查询和解析器需要看起来像什么?我用Google搜索但尚未找到示例.在此先感谢您的任何信息.

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

export default compose(
  graphql(query1, 
  ....),
  graphql(query2, 
  ....),
  graphql(query3, 
  ....),
  withApollo
)(PrintListEditPage)
Run Code Online (Sandbox Code Playgroud)

有没有办法让这样的多个声明:

const withMutations = graphql(updateName, {
  props({ mutate }) {
    return {
      updatePrintListName({ printListId, name }) {
        return mutate({
          variables: { printListId, name },
        });
      },
    };
  },
});
Run Code Online (Sandbox Code Playgroud)

......来电话之前来的export default compose

Dan*_* R. 19

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

import { graphql, compose } from 'react-apollo'

export default compose(
  graphql(mutation1, { name: 'createSomething' }),
  graphql(mutation2, { name: 'deleteSomething' }),
)(Component)
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅完整的API.