@@ -36,6 +36,7 @@ import {
3636 getIsFile ,
3737 getFile ,
3838 getHeaders ,
39+ getIsReloadingSchema ,
3940} from '../state/sessions/selectors'
4041import { getHistoryOpen } from '../state/general/selectors'
4142import {
@@ -82,6 +83,7 @@ export interface Props {
8283 configPath ?: string
8384 createApolloLink ?: ( session : Session ) => ApolloLink
8485 workspaceName ?: string
86+ shouldInjectHeaders : boolean
8587}
8688
8789export interface ReduxProps {
@@ -98,6 +100,7 @@ export interface ReduxProps {
98100 setConfigString : ( str : string ) => void
99101 schemaFetchingError : ( endpoint : string , error : string ) => void
100102 schemaFetchingSuccess : ( endpoint : string , tracingSupported : boolean ) => void
103+ isReloadingSchema : boolean
101104 isConfigTab : boolean
102105 isSettingsTab : boolean
103106 isFile : boolean
@@ -148,8 +151,10 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
148151 componentWillMount ( ) {
149152 // init redux
150153 this . props . initState ( getWorkspaceId ( this . props ) , this . props . endpoint )
151- this . props . injectHeaders ( this . props . headers , this . props . endpoint )
152154 this . props . setConfigString ( this . props . configString )
155+ if ( this . props . shouldInjectHeaders ) {
156+ this . props . injectHeaders ( this . props . headers , this . props . endpoint )
157+ }
153158 }
154159
155160 componentDidMount ( ) {
@@ -168,10 +173,16 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
168173 if (
169174 nextProps . headers !== this . props . headers ||
170175 nextProps . endpoint !== this . props . endpoint ||
171- nextProps . workspaceName !== this . props . workspaceName
176+ nextProps . workspaceName !== this . props . workspaceName ||
177+ nextProps . sessionHeaders !== this . props . sessionHeaders
172178 ) {
173179 this . getSchema ( nextProps )
174180 }
181+ if ( this . props . isReloadingSchema && ! nextProps . isReloadingSchema ) {
182+ setTimeout ( ( ) => {
183+ this . getSchema ( nextProps )
184+ } )
185+ }
175186 if (
176187 this . props . endpoint !== nextProps . endpoint ||
177188 this . props . configPath !== nextProps . configPath ||
@@ -182,7 +193,10 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
182193 if ( this . props . subscriptionEndpoint !== nextProps . subscriptionEndpoint ) {
183194 setSubscriptionEndpoint ( nextProps . subscriptionEndpoint )
184195 }
185- if ( nextProps . headers !== this . props . headers ) {
196+ if (
197+ nextProps . headers !== this . props . headers &&
198+ this . props . shouldInjectHeaders
199+ ) {
186200 this . props . injectHeaders ( nextProps . headers , nextProps . endpoint )
187201 }
188202 if ( nextProps . configString !== this . props . configString ) {
@@ -195,6 +209,9 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
195209 this . setState ( { schema : undefined } )
196210 }
197211 let first = true
212+ if ( this . backoff ) {
213+ this . backoff . stop ( )
214+ }
198215 this . backoff = new Backoff ( async ( ) => {
199216 if ( first ) {
200217 await this . schemaGetter ( props )
@@ -211,9 +228,10 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
211228 try {
212229 const data = {
213230 endpoint : props . endpoint ,
214- headers : props . headers
215- ? JSON . stringify ( props . headers )
216- : props . sessionHeaders ,
231+ headers :
232+ props . sessionHeaders && props . sessionHeaders . length > 0
233+ ? props . sessionHeaders
234+ : JSON . stringify ( props . headers ) ,
217235 }
218236 const schema = await schemaFetcher . fetch ( data )
219237 if ( schema ) {
@@ -225,6 +243,8 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
225243 this . backoff . stop ( )
226244 }
227245 } catch ( e ) {
246+ // tslint:disable-next-line
247+ console . error ( e )
228248 this . props . schemaFetchingError ( props . endpoint , e . message )
229249 }
230250 }
@@ -322,6 +342,7 @@ const mapStateToProps = createStructuredSelector({
322342 sessionHeaders : getHeaders ,
323343 settings : getSettings ,
324344 settingsString : getSettingsString ,
345+ isReloadingSchema : getIsReloadingSchema ,
325346} )
326347
327348export default connect ( mapStateToProps , {
0 commit comments