@@ -44,6 +44,7 @@ import {
44
44
import { Session } from '../state/sessions/reducers'
45
45
import { getWorkspaceId } from './Playground/util/getWorkspaceId'
46
46
import { getSettings , getSettingsString } from '../state/workspace/reducers'
47
+ import { schemaFetchingError , schemaFetchingSuccess } from '../lib'
47
48
48
49
export interface Response {
49
50
resultID : string
@@ -93,6 +94,8 @@ export interface ReduxProps {
93
94
setTracingSupported : ( value : boolean ) => void
94
95
injectHeaders : ( headers : string , endpoint : string ) => void
95
96
setConfigString : ( str : string ) => void
97
+ schemaFetchingError : ( endpoint : string ) => void
98
+ schemaFetchingSuccess : ( endpoint : string , tracingSupported : boolean ) => void
96
99
isConfigTab : boolean
97
100
isSettingsTab : boolean
98
101
isFile : boolean
@@ -120,6 +123,8 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
120
123
graphiqlComponents : any [ ] = [ ]
121
124
private initialIndex : number = - 1
122
125
private mounted = false
126
+ private retries = 0
127
+ private maxRetries = 10
123
128
124
129
constructor ( props : Props & ReduxProps ) {
125
130
super ( props )
@@ -187,15 +192,27 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
187
192
if ( this . mounted && this . state . schema ) {
188
193
this . setState ( { schema : undefined } )
189
194
}
190
- const schema = await schemaFetcher . fetch ( {
191
- endpoint : props . endpoint ,
192
- headers : props . headers
193
- ? JSON . stringify ( props . headers )
194
- : props . sessionHeaders ,
195
- } )
196
- if ( schema ) {
197
- this . setState ( { schema : schema . schema } )
198
- this . props . setTracingSupported ( schema . tracingSupported )
195
+ try {
196
+ const schema = await schemaFetcher . fetch ( {
197
+ endpoint : props . endpoint ,
198
+ headers : props . headers
199
+ ? JSON . stringify ( props . headers )
200
+ : props . sessionHeaders ,
201
+ } )
202
+ if ( schema ) {
203
+ this . setState ( { schema : schema . schema } )
204
+ this . props . schemaFetchingSuccess (
205
+ props . endpoint ,
206
+ schema . tracingSupported ,
207
+ )
208
+ }
209
+ } catch ( e ) {
210
+ this . props . schemaFetchingError ( props . endpoint )
211
+ if ( this . retries < this . maxRetries ) {
212
+ await new Promise ( r => setTimeout ( r , 5000 ) )
213
+ this . retries ++
214
+ this . getSchema ( props )
215
+ }
199
216
}
200
217
}
201
218
@@ -305,6 +322,8 @@ export default connect(mapStateToProps, {
305
322
setTracingSupported,
306
323
injectHeaders,
307
324
setConfigString,
325
+ schemaFetchingError,
326
+ schemaFetchingSuccess,
308
327
} ) ( Playground )
309
328
310
329
const PlaygroundWrapper = styled . div `
0 commit comments