Fix flow error

This commit is contained in:
Gregory Schier 2017-08-14 12:04:46 -07:00
parent a570b3c1f8
commit eb0faa011e

View File

@ -89,51 +89,51 @@ class GraphQLEditor extends React.PureComponent {
schemaIsFetching: false schemaIsFetching: false
}; };
let request: RenderedRequest; let request: RenderedRequest | null = null;
try { try {
request = await getRenderedRequest(rawRequest, environmentId); request = await getRenderedRequest(rawRequest, environmentId);
} catch (err) { } catch (err) {
newState.schemaFetchError = `Failed to fetch schema: ${err}`; newState.schemaFetchError = `Failed to fetch schema: ${err}`;
this.setState(newState);
return;
} }
try { if (request) {
// TODO: Use Insomnia's network stack to handle things like authentication try {
const bodyJson = JSON.stringify({query: introspectionQuery}); // TODO: Use Insomnia's network stack to handle things like authentication
const introspectionRequest = Object.assign({}, request, { const bodyJson = JSON.stringify({query: introspectionQuery});
body: newBodyRaw(bodyJson, CONTENT_TYPE_JSON), 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 // 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. // like we are by setting these properties to prevent bugs in the future.
_id: request._id + '.graphql', _id: request._id + '.graphql',
parentId: request._id parentId: request._id
}); });
const {bodyBuffer, response} = await network._actuallySend( const {bodyBuffer, response} = await network._actuallySend(
introspectionRequest, introspectionRequest,
workspace, workspace,
settings settings
); );
const status = response.statusCode || 0; const status = response.statusCode || 0;
if (response.error) { if (response.error) {
newState.schemaFetchError = response.error; newState.schemaFetchError = response.error;
} else if (status < 200 || status >= 300) { } else if (status < 200 || status >= 300) {
const msg = `Got status ${status} fetching schema from "${request.url}"`; const msg = `Got status ${status} fetching schema from "${request.url}"`;
newState.schemaFetchError = msg; newState.schemaFetchError = msg;
} else if (bodyBuffer) { } else if (bodyBuffer) {
const {data} = JSON.parse(bodyBuffer.toString()); const {data} = JSON.parse(bodyBuffer.toString());
const schema = buildClientSchema(data); const schema = buildClientSchema(data);
newState.schema = schema; newState.schema = schema;
newState.schemaLastFetchTime = Date.now(); newState.schemaLastFetchTime = Date.now();
} else { } else {
newState.schemaFetchError = 'No response body received when fetching schema'; 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) { if (this._isMounted) {