Apollo GraphQL:子组件重新运行父查询?
Apollo GraphQL: Child Component Re-Runs Parent Query?
我有一个附加了 Apollo 查询的父组件:
const withData = graphql(MY_QUERY, {
options({ userID }) {
return {
variables: { _id: userID}
};
},
props({ data: { loading, getOneUser } }) {
return { loading, getOneUser };
},
});
export default compose(
withData,
withApollo
)(NavigatorsList);
export { getOneUser_QUERY };
我在渲染函数中嵌入了一个名为 userPhoto
的子组件:
return (
<div>
<userPhoto />
[.....]
</div>
)
没有子组件,withData GraphQL 函数运行两次,一次用于 loading == true
,另一次返回数据。
包含子组件后,withData GraphQL 函数运行三次。第三次 getOneUser
未定义,我的组件抛出错误。
我该如何纠正?
提前感谢大家提供的任何信息。
已修复。子组件中存在语法错误,该错误并未抛出错误,但导致查询 运行 两次 + 其他各种异常。
我有一个附加了 Apollo 查询的父组件:
const withData = graphql(MY_QUERY, {
options({ userID }) {
return {
variables: { _id: userID}
};
},
props({ data: { loading, getOneUser } }) {
return { loading, getOneUser };
},
});
export default compose(
withData,
withApollo
)(NavigatorsList);
export { getOneUser_QUERY };
我在渲染函数中嵌入了一个名为 userPhoto
的子组件:
return (
<div>
<userPhoto />
[.....]
</div>
)
没有子组件,withData GraphQL 函数运行两次,一次用于 loading == true
,另一次返回数据。
包含子组件后,withData GraphQL 函数运行三次。第三次 getOneUser
未定义,我的组件抛出错误。
我该如何纠正?
提前感谢大家提供的任何信息。
已修复。子组件中存在语法错误,该错误并未抛出错误,但导致查询 运行 两次 + 其他各种异常。