From eb0faa011ed849fd6c455d5decccf4f7ad100fb5 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 14 Aug 2017 12:04:46 -0700 Subject: [PATCH] Fix flow error --- .../editors/body/graph-ql-editor.js | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/app/ui/components/editors/body/graph-ql-editor.js b/app/ui/components/editors/body/graph-ql-editor.js index e5c36edd8..826ec409f 100644 --- a/app/ui/components/editors/body/graph-ql-editor.js +++ b/app/ui/components/editors/body/graph-ql-editor.js @@ -89,51 +89,51 @@ class GraphQLEditor extends React.PureComponent { schemaIsFetching: false }; - let request: RenderedRequest; + let request: RenderedRequest | null = null; try { request = await getRenderedRequest(rawRequest, environmentId); } catch (err) { newState.schemaFetchError = `Failed to fetch schema: ${err}`; - this.setState(newState); - return; } - try { - // TODO: Use Insomnia's network stack to handle things like authentication - const bodyJson = JSON.stringify({query: introspectionQuery}); - const introspectionRequest = Object.assign({}, request, { - body: newBodyRaw(bodyJson, CONTENT_TYPE_JSON), + if (request) { + try { + // TODO: Use Insomnia's network stack to handle things like authentication + const bodyJson = JSON.stringify({query: introspectionQuery}); + const introspectionRequest = Object.assign({}, request, { + body: newBodyRaw(bodyJson, CONTENT_TYPE_JSON), - // NOTE: We're not actually saving this request or response but let's pretend - // like we are by setting these properties to prevent bugs in the future. - _id: request._id + '.graphql', - parentId: request._id - }); + // NOTE: We're not actually saving this request or response but let's pretend + // like we are by setting these properties to prevent bugs in the future. + _id: request._id + '.graphql', + parentId: request._id + }); - const {bodyBuffer, response} = await network._actuallySend( - introspectionRequest, - workspace, - settings - ); + const {bodyBuffer, response} = await network._actuallySend( + introspectionRequest, + workspace, + settings + ); - const status = response.statusCode || 0; + const status = response.statusCode || 0; - if (response.error) { - newState.schemaFetchError = response.error; - } else if (status < 200 || status >= 300) { - const msg = `Got status ${status} fetching schema from "${request.url}"`; - newState.schemaFetchError = msg; - } else if (bodyBuffer) { - const {data} = JSON.parse(bodyBuffer.toString()); - const schema = buildClientSchema(data); - newState.schema = schema; - newState.schemaLastFetchTime = Date.now(); - } else { - newState.schemaFetchError = 'No response body received when fetching schema'; + if (response.error) { + newState.schemaFetchError = response.error; + } else if (status < 200 || status >= 300) { + const msg = `Got status ${status} fetching schema from "${request.url}"`; + newState.schemaFetchError = msg; + } else if (bodyBuffer) { + const {data} = JSON.parse(bodyBuffer.toString()); + const schema = buildClientSchema(data); + newState.schema = schema; + newState.schemaLastFetchTime = Date.now(); + } else { + newState.schemaFetchError = 'No response body received when fetching schema'; + } + } catch (err) { + console.warn(`Failed to fetch GraphQL schema from ${request.url}`, err); + newState.schemaFetchError = `Failed to contact "${request.url}" to fetch schema`; } - } catch (err) { - console.warn(`Failed to fetch GraphQL schema from ${request.url}`, err); - newState.schemaFetchError = `Failed to contact "${request.url}" to fetch schema`; } if (this._isMounted) {