【发布时间】:2018-03-26 07:17:34
【问题描述】:
我有以下 apollo-graphql 客户端代码,其中我每 30 秒触发一次 graphql 查询并获取数据。
import React, { Component } from 'react';
import { gql, graphql } from 'react-apollo';
import _ from 'underscore';
class Test extends Component {
render() {
if (this.props.TestData.loading) {
return <div>Loading...</div>
}
if (this.props.TestData.error && this.props.TestData.error !== null) {
return <div>Error...</div>
}
// Iterate through the this.props.TestData.getTestData and build the Table of data here
return (
<table>
_.map(this.props.TestData.getTestData.testList, (test) => {
<tr>
<td>{test.testName}</td>
<td>{test.status}</td>
</tr>
})
</table>
);
}
}
const TestQuery = gql`
query TestQuery() {
getTestData() {
testList {
testName
status
}
}
}
`;
const options = () => ({
pollInterval: 30000,
});
const withTestData = graphql(TestQuery, {
name: 'TestData',
options,
});
export default withTestData(Test);
我面临的问题是每 30 秒后我都会看到 Loading...,因为查询被重新触发。我希望 Loading... 仅在页面启动时显示,此后它应该是平滑更新,我不想向用户显示 Loading... 指示器。不知道如何实现。
【问题讨论】:
标签: graphql apollo react-apollo apollo-client