Apollo GraphQL:一个组件中的多个查询?
Apollo GraphQL: Multiple Queries in One Component?
我有一个组件需要查询两个完全独立的表。在这种情况下,模式、查询和解析器需要是什么样的?我用谷歌搜索但还没有找到例子。提前感谢您提供任何信息。
更新:
在 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
函数采用可选的第二个参数,允许您为传递的 属性 名称起别名。如果您有多个突变,您可以根据需要使用 name
属性 重命名 mutate
:
import { graphql, compose } from 'react-apollo'
export default compose(
graphql(mutation1, { name: 'createSomething' }),
graphql(mutation2, { name: 'deleteSomething' }),
)(Component)
有关详细信息,请参阅 the complete API。
我有一个组件需要查询两个完全独立的表。在这种情况下,模式、查询和解析器需要是什么样的?我用谷歌搜索但还没有找到例子。提前感谢您提供任何信息。
更新:
在 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
函数采用可选的第二个参数,允许您为传递的 属性 名称起别名。如果您有多个突变,您可以根据需要使用 name
属性 重命名 mutate
:
import { graphql, compose } from 'react-apollo'
export default compose(
graphql(mutation1, { name: 'createSomething' }),
graphql(mutation2, { name: 'deleteSomething' }),
)(Component)
有关详细信息,请参阅 the complete API。