Skip to content

Commit 94e54fe

Browse files
committed
fix schema reloading
1 parent 6849925 commit 94e54fe

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

packages/graphql-playground-react/src/components/Playground/TopBar/TopBar.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import * as PropTypes from 'prop-types'
2121
import {
2222
editEndpoint,
2323
prettifyQuery,
24-
fetchSchema,
24+
refetchSchema,
2525
} from '../../../state/sessions/actions'
2626
import { share } from '../../../state/sharing/actions'
2727
import { openHistory } from '../../../state/general/actions'
@@ -36,7 +36,7 @@ export interface Props {
3636
prettifyQuery: () => void
3737
openHistory: () => void
3838
share: () => void
39-
fetchSchema: () => void
39+
refetchSchema: () => void
4040
}
4141

4242
class TopBar extends React.Component<Props, {}> {
@@ -58,7 +58,7 @@ class TopBar extends React.Component<Props, {}> {
5858
value={this.props.endpoint}
5959
onChange={this.onChange}
6060
onKeyDown={this.onKeyDown}
61-
onBlur={this.fetchSchema}
61+
onBlur={this.props.refetchSchema}
6262
disabled={this.props.fixedEndpoint}
6363
className={cx({ active: !this.props.fixedEndpoint })}
6464
/>
@@ -70,7 +70,7 @@ class TopBar extends React.Component<Props, {}> {
7070
) : (
7171
<ReloadIcon
7272
isReloadingSchema={this.props.isReloadingSchema}
73-
onReloadSchema={this.fetchSchema}
73+
onReloadSchema={this.props.refetchSchema}
7474
/>
7575
)}
7676
</UrlBarWrapper>
@@ -90,12 +90,9 @@ class TopBar extends React.Component<Props, {}> {
9090
}
9191
onKeyDown = e => {
9292
if (e.keyCode === 13) {
93-
this.fetchSchema()
93+
this.props.refetchSchema()
9494
}
9595
}
96-
fetchSchema = () => {
97-
this.props.fetchSchema()
98-
}
9996
openHistory = () => {
10097
this.props.openHistory()
10198
}
@@ -152,7 +149,7 @@ export default connect(mapStateToProps, {
152149
prettifyQuery,
153150
openHistory,
154151
share,
155-
fetchSchema,
152+
refetchSchema,
156153
})(TopBar)
157154

158155
const buttonColor = theme('mode', {

packages/graphql-playground-react/src/components/ProjectsSideNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { connect } from 'react-redux'
1111
import { getSessionCounts } from '../state/workspace/reducers'
1212
import { Map } from 'immutable'
1313
import { getWorkspaceId } from './Playground/util/getWorkspaceId'
14-
import { openConfigTab } from '../lib'
14+
import { openConfigTab } from '../state/sessions/actions'
1515

1616
export interface Props {
1717
config: GraphQLConfig

packages/graphql-playground-react/src/state/sessions/actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const {
6060
setResponseExtensions,
6161
setCurrentQueryStartTime,
6262
setCurrentQueryEndTime,
63+
refetchSchema,
6364
} = createActions({
6465
// simple property setting
6566
EDIT_QUERY: query => ({ query }),
@@ -120,6 +121,7 @@ export const {
120121
CLEAR_RESPONSES: simpleAction(),
121122

122123
FETCH_SCHEMA: simpleAction(),
124+
REFETCH_SCHEMA: simpleAction(),
123125
SCHEMA_FETCHING_SUCCESS: (endpoint, tracingSupported) => ({
124126
endpoint,
125127
tracingSupported,

packages/graphql-playground-react/src/state/sessions/reducers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ const reducer = handleActions(
258258
true,
259259
)
260260
},
261+
REFETCH_SCHEMA: state => {
262+
return state.setIn(
263+
['sessions', getSelectedSessionId(state), 'isReloadingSchema'],
264+
true,
265+
)
266+
},
261267
STOP_QUERY: (state, { payload: { sessionId } }) => {
262268
return state.mergeIn(['sessions', sessionId], {
263269
queryRunning: false,

packages/graphql-playground-react/src/state/sessions/sagas.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ function* fetchSchemaSaga() {
112112
}
113113
}
114114

115+
function* refetchSchemaSaga() {
116+
const session: Session = yield select(getSelectedSession)
117+
yield schemaFetcher.refetch(session)
118+
try {
119+
yield put(schemaFetchingSuccess(session.endpoint))
120+
} catch (e) {
121+
yield put(schemaFetchingError(session.endpoint))
122+
yield call(delay, 5000)
123+
yield put(fetchSchema())
124+
}
125+
}
126+
115127
function* renewStacks() {
116128
const session: Session = yield select(getSelectedSession)
117129
const docs: DocsSessionState = yield select(getSessionDocsState)
@@ -146,6 +158,7 @@ export const sessionsSagas = [
146158
takeEvery('EDIT_QUERY', safely(setQueryFacts)),
147159
takeEvery('RUN_QUERY_AT_POSITION', safely(runQueryAtPosition)),
148160
takeLatest('FETCH_SCHEMA', safely(fetchSchemaSaga)),
161+
takeLatest('REFETCH_SCHEMA', safely(refetchSchemaSaga)),
149162
takeLatest('SCHEMA_FETCHING_SUCCESS', safely(renewStacks)),
150163
takeEvery('QUERY_SUCCESS' as any, safely(addToHistory)),
151164
]

0 commit comments

Comments
 (0)