Skip to content

Commit eb0faa0

Browse files
committedAug 14, 2017
Fix flow error
1 parent a570b3c commit eb0faa0

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed
 

‎app/ui/components/editors/body/graph-ql-editor.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -89,51 +89,51 @@ class GraphQLEditor extends React.PureComponent {
8989
schemaIsFetching: false
9090
};
9191

92-
let request: RenderedRequest;
92+
let request: RenderedRequest | null = null;
9393
try {
9494
request = await getRenderedRequest(rawRequest, environmentId);
9595
} catch (err) {
9696
newState.schemaFetchError = `Failed to fetch schema: ${err}`;
97-
this.setState(newState);
98-
return;
9997
}
10098

101-
try {
102-
// TODO: Use Insomnia's network stack to handle things like authentication
103-
const bodyJson = JSON.stringify({query: introspectionQuery});
104-
const introspectionRequest = Object.assign({}, request, {
105-
body: newBodyRaw(bodyJson, CONTENT_TYPE_JSON),
106-
107-
// NOTE: We're not actually saving this request or response but let's pretend
108-
// like we are by setting these properties to prevent bugs in the future.
109-
_id: request._id + '.graphql',
110-
parentId: request._id
111-
});
112-
113-
const {bodyBuffer, response} = await network._actuallySend(
114-
introspectionRequest,
115-
workspace,
116-
settings
117-
);
118-
119-
const status = response.statusCode || 0;
120-
121-
if (response.error) {
122-
newState.schemaFetchError = response.error;
123-
} else if (status < 200 || status >= 300) {
124-
const msg = `Got status ${status} fetching schema from "${request.url}"`;
125-
newState.schemaFetchError = msg;
126-
} else if (bodyBuffer) {
127-
const {data} = JSON.parse(bodyBuffer.toString());
128-
const schema = buildClientSchema(data);
129-
newState.schema = schema;
130-
newState.schemaLastFetchTime = Date.now();
131-
} else {
132-
newState.schemaFetchError = 'No response body received when fetching schema';
99+
if (request) {
100+
try {
101+
// TODO: Use Insomnia's network stack to handle things like authentication
102+
const bodyJson = JSON.stringify({query: introspectionQuery});
103+
const introspectionRequest = Object.assign({}, request, {
104+
body: newBodyRaw(bodyJson, CONTENT_TYPE_JSON),
105+
106+
// NOTE: We're not actually saving this request or response but let's pretend
107+
// like we are by setting these properties to prevent bugs in the future.
108+
_id: request._id + '.graphql',
109+
parentId: request._id
110+
});
111+
112+
const {bodyBuffer, response} = await network._actuallySend(
113+
introspectionRequest,
114+
workspace,
115+
settings
116+
);
117+
118+
const status = response.statusCode || 0;
119+
120+
if (response.error) {
121+
newState.schemaFetchError = response.error;
122+
} else if (status < 200 || status >= 300) {
123+
const msg = `Got status ${status} fetching schema from "${request.url}"`;
124+
newState.schemaFetchError = msg;
125+
} else if (bodyBuffer) {
126+
const {data} = JSON.parse(bodyBuffer.toString());
127+
const schema = buildClientSchema(data);
128+
newState.schema = schema;
129+
newState.schemaLastFetchTime = Date.now();
130+
} else {
131+
newState.schemaFetchError = 'No response body received when fetching schema';
132+
}
133+
} catch (err) {
134+
console.warn(`Failed to fetch GraphQL schema from ${request.url}`, err);
135+
newState.schemaFetchError = `Failed to contact "${request.url}" to fetch schema`;
133136
}
134-
} catch (err) {
135-
console.warn(`Failed to fetch GraphQL schema from ${request.url}`, err);
136-
newState.schemaFetchError = `Failed to contact "${request.url}" to fetch schema`;
137137
}
138138

139139
if (this._isMounted) {

0 commit comments

Comments
 (0)
Please sign in to comment.