@@ -44,6 +44,7 @@ import {
4444import { Session } from '../state/sessions/reducers'
4545import { getWorkspaceId } from './Playground/util/getWorkspaceId'
4646import { getSettings , getSettingsString } from '../state/workspace/reducers'
47+ import { schemaFetchingError , schemaFetchingSuccess } from '../lib'
4748
4849export interface Response {
4950 resultID : string
@@ -93,6 +94,8 @@ export interface ReduxProps {
9394 setTracingSupported : ( value : boolean ) => void
9495 injectHeaders : ( headers : string , endpoint : string ) => void
9596 setConfigString : ( str : string ) => void
97+ schemaFetchingError : ( endpoint : string ) => void
98+ schemaFetchingSuccess : ( endpoint : string , tracingSupported : boolean ) => void
9699 isConfigTab : boolean
97100 isSettingsTab : boolean
98101 isFile : boolean
@@ -120,6 +123,8 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
120123 graphiqlComponents : any [ ] = [ ]
121124 private initialIndex : number = - 1
122125 private mounted = false
126+ private retries = 0
127+ private maxRetries = 10
123128
124129 constructor ( props : Props & ReduxProps ) {
125130 super ( props )
@@ -187,15 +192,27 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
187192 if ( this . mounted && this . state . schema ) {
188193 this . setState ( { schema : undefined } )
189194 }
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+ }
199216 }
200217 }
201218
@@ -305,6 +322,8 @@ export default connect(mapStateToProps, {
305322 setTracingSupported,
306323 injectHeaders,
307324 setConfigString,
325+ schemaFetchingError,
326+ schemaFetchingSuccess,
308327} ) ( Playground )
309328
310329const PlaygroundWrapper = styled . div `
0 commit comments