From 03cb3e45fd091e43c3560c2f51dba0d87ae40a32 Mon Sep 17 00:00:00 2001 From: wawhal Date: Tue, 9 Jul 2019 15:21:44 +0530 Subject: [PATCH] reduce the number of introspection queries --- .../OneGraphExplorer/OneGraphExplorer.js | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/console/src/components/Services/ApiExplorer/OneGraphExplorer/OneGraphExplorer.js b/console/src/components/Services/ApiExplorer/OneGraphExplorer/OneGraphExplorer.js index d2d19a067696f..debb1bb3dd8d1 100644 --- a/console/src/components/Services/ApiExplorer/OneGraphExplorer/OneGraphExplorer.js +++ b/console/src/components/Services/ApiExplorer/OneGraphExplorer/OneGraphExplorer.js @@ -26,7 +26,7 @@ class OneGraphExplorer extends React.Component { schema: null, query: undefined, isResizing: false, - headers: this.props.headers || [], + loading: false, }; componentDidMount() { @@ -34,8 +34,10 @@ class OneGraphExplorer extends React.Component { this.introspect(); } - componentDidUpdate() { - if (this.shouldIntrospect()) { + componentDidUpdate(prevProps) { + if ( + JSON.stringify(prevProps.headers) !== JSON.stringify(this.props.headers) + ) { this.introspect(); } } @@ -71,15 +73,9 @@ class OneGraphExplorer extends React.Component { } } - shouldIntrospect() { - return ( - JSON.stringify(this.props.headers) !== JSON.stringify(this.state.headers) - ); - } - introspect() { const { endpoint, headers } = this.props; - + this.setState({ loading: true }); fetch(endpoint, { method: 'POST', headers: getHeadersAsJSON(headers || []), @@ -91,13 +87,13 @@ class OneGraphExplorer extends React.Component { .then(result => { this.setState({ schema: buildClientSchema(result.data), - headers: JSON.parse(JSON.stringify(headers)), + loading: false, }); }) .catch(() => { this.setState({ schema: null, - headers: JSON.parse(JSON.stringify(headers)), + loading: false, }); }); }