@@ -89,51 +89,51 @@ class GraphQLEditor extends React.PureComponent {
89
89
schemaIsFetching : false
90
90
} ;
91
91
92
- let request : RenderedRequest ;
92
+ let request : RenderedRequest | null = null ;
93
93
try {
94
94
request = await getRenderedRequest ( rawRequest , environmentId ) ;
95
95
} catch ( err ) {
96
96
newState . schemaFetchError = `Failed to fetch schema: ${ err } ` ;
97
- this . setState ( newState ) ;
98
- return ;
99
97
}
100
98
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` ;
133
136
}
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` ;
137
137
}
138
138
139
139
if ( this . _isMounted ) {
0 commit comments