From 9eb804309db8f14a2e2deb108f09efd2fcdd22b8 Mon Sep 17 00:00:00 2001 From: wawhal Date: Fri, 15 Mar 2019 14:59:00 +0530 Subject: [PATCH 1/3] v0.2.2 --- community/tools/graphql2chartjs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community/tools/graphql2chartjs/package.json b/community/tools/graphql2chartjs/package.json index 39cf700862de4..a442b034df14f 100644 --- a/community/tools/graphql2chartjs/package.json +++ b/community/tools/graphql2chartjs/package.json @@ -1,6 +1,6 @@ { "name": "graphql2chartjs", - "version": "0.2.1", + "version": "0.2.2", "description": "", "main": "lib/index.js", "scripts": { From 55e9232bb75a29293bbe7cddb48797cda3a5e18d Mon Sep 17 00:00:00 2001 From: wawhal Date: Mon, 18 Mar 2019 21:30:28 +0530 Subject: [PATCH 2/3] fix a bug where header change would not reload explorer schema --- .../components/ApiExplorer/GraphiQLWrapper.js | 1 + .../ApiExplorer/OneGraphExplorer.js | 39 ++++++++++++++++++- console/src/components/ApiExplorer/utils.js | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/console/src/components/ApiExplorer/GraphiQLWrapper.js b/console/src/components/ApiExplorer/GraphiQLWrapper.js index b26ebab1c0778..9c4d21cc05ff7 100644 --- a/console/src/components/ApiExplorer/GraphiQLWrapper.js +++ b/console/src/components/ApiExplorer/GraphiQLWrapper.js @@ -143,6 +143,7 @@ class GraphiQLWrapper extends Component { renderGraphiql={renderGraphiql} endpoint={graphqlNetworkData.url} headers={graphqlNetworkData.headers} + headerFocus={headerFocus} query={queryString} /> diff --git a/console/src/components/ApiExplorer/OneGraphExplorer.js b/console/src/components/ApiExplorer/OneGraphExplorer.js index b9140a03c63c0..ba92177ab3de0 100644 --- a/console/src/components/ApiExplorer/OneGraphExplorer.js +++ b/console/src/components/ApiExplorer/OneGraphExplorer.js @@ -19,9 +19,39 @@ class OneGraphExplorer extends React.Component { schema: null, query: this.props.query, isResizing: false, + headers: [] }; componentDidMount() { + this.introspect(); + } + + componentDidUpdate() { + if (this.shouldIntrospect(this.props.headers, this.state.headers)) { + this.introspect() + } + } + + shouldIntrospect(newHeadersArray, oldHeadersArray) { + if (this.props.headerFocus) { + return false; + } + const oldHeaders = getHeadersAsJSON(oldHeadersArray); + const headers = getHeadersAsJSON(newHeadersArray); + if (Object.keys(oldHeaders).length !== Object.keys(headers).length) { + return true; + } + for (var i = Object.keys(headers).length - 1; i >= 0; i--) { + const key = Object.keys(headers)[i]; + const value = headers[key]; + if (oldHeaders[key] !== value) { + return true; + } + } + return false; + } + + introspect() { const { endpoint, headers } = this.props; fetch(endpoint, { method: 'POST', @@ -34,8 +64,15 @@ class OneGraphExplorer extends React.Component { .then(result => { this.setState({ schema: buildClientSchema(result.data), + headers: JSON.parse(JSON.stringify(headers)) }); - }); + }) + .catch(error => { + this.setState({ + schema: null, + headers: JSON.parse(JSON.stringify(headers)) + }); + }) } onExplorerResize = e => { diff --git a/console/src/components/ApiExplorer/utils.js b/console/src/components/ApiExplorer/utils.js index 9c6e812625627..937a83180dd9f 100644 --- a/console/src/components/ApiExplorer/utils.js +++ b/console/src/components/ApiExplorer/utils.js @@ -1,4 +1,4 @@ -const getHeadersAsJSON = headers => { +const getHeadersAsJSON = (headers = []) => { const headerJSON = {}; const nonEmptyHeaders = headers.filter(header => { return header.key && header.isActive; From 1816aef45929cc1266d4f30781d2000347398320 Mon Sep 17 00:00:00 2001 From: wawhal Date: Mon, 18 Mar 2019 23:18:06 +0530 Subject: [PATCH 3/3] revert unnecessary changes --- community/tools/graphql2chartjs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community/tools/graphql2chartjs/package.json b/community/tools/graphql2chartjs/package.json index a442b034df14f..39cf700862de4 100644 --- a/community/tools/graphql2chartjs/package.json +++ b/community/tools/graphql2chartjs/package.json @@ -1,6 +1,6 @@ { "name": "graphql2chartjs", - "version": "0.2.2", + "version": "0.2.1", "description": "", "main": "lib/index.js", "scripts": {