【发布时间】:2018-02-16 08:54:57
【问题描述】:
所以通常我对使用 apollo react 和 GraphQL 查询或变异数据没有任何问题。但有一件事我只是不明白:假设我有一个查询得到一个任意实体的 Id,如下所示:
const Query = graphql(
baseNodeQuery([
'entityId',
'entityLabel'
], 'employment_reference_preset'), {
options: {
variables: {
filter: {
type: "employment_reference_preset"
},
limit: 1000,
offset: 0
}
}
})
(ExampleComponent);
baseNodeQuery 是一个自定义函数,它接受一些参数来使用 gql() 准备查询。但无论如何,在我的 ExampleComponent 中,我可以使用这样的数据:
const EmploymentReferencePresetEntity = ({data: {loading, error, nodeQuery}}) => {
if (loading) {
return <p>Loading...</p>;
}
if (error) {
return <p>{error.message}</p>;
}
return (
<div>
//do something with the data form nodeQuery
</div>
)
};
但是,当我想使用从上一个查询中获得的 Id 进行第二次查询并将该 Id 用作过滤器时呢?当我像以前一样在我的 ExampleComponent 中返回另一个 graphql 查询时,我收到一个错误,即我没有返回有效的反应组件。那我该怎么做呢?
提前致谢!
【问题讨论】:
标签: reactjs graphql react-apollo