【发布时间】:2019-02-08 06:04:52
【问题描述】:
我正在尝试将 QueryRenderer 与我打算用于分页的随附片段结合使用 Relay 的 createPaginationContainer 高阶组件。
我在传递给 QueryRenderer 的查询中使用了一个片段。例如
<QueryRenderer
environment={environment}
query={
graphql`
query MyComponentQuery($count: Int!, $cursor: String) {
...MyComponent_students @arguments(count: $count, cursor: $cursor)
}
`
}
variables={{count: 10}}
render={(p) => {
console.log('render of QueryRenderer');
console.log(p);
return (<MyComponent {...p.props} error={p.error} />);
}}/>
此查询已成功执行 - 我可以在网络选项卡中看到,作为执行此 GraphQL 查询的结果,从服务器返回了预期的 JSON。
但是,我完全无法在 QueryRenderer 的 query 属性的上下文中看到查询结果(请注意上面 sn-p 中的日志记录)。这是console.log(p) 的输出。
{…}
error: null
props: {…}
__fragments: {…}
MyComponent_students: {…}
count: 10
cursor: null
<prototype>: Object { … }
<prototype>: Object { … }
__id: "client:root"
<prototype>: Object { … }
retry: function retry()
<prototype>: Object { … }
这会阻止我将查询结果传递给 paginationContainer(在本例中为 MyComponent)。
为什么会发生这种情况,如何解决?
作为参考,片段MyComponent_students定义为:
fragment MyComponent_students on Query
@argumentDefinitions(
count: {type: "Int", defaultValue: 10}
cursor: {type: "String"}
) {
students(
first: $count
after: $cursor
) @connection(key: "MyComponent_students") {
edges {
node {
id
createdAt
}
}
}
}
【问题讨论】:
标签: reactjs graphql relayjs relay