Skip to content

Commit 7f077c6

Browse files
committed
Reload schema
1 parent 41b1f0b commit 7f077c6

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

packages/graphql-playground-electron/src/main/menu.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ export const buildTemplate = (
8282
accelerator: 'Cmd+S',
8383
click: () => send('File', 'Save'),
8484
},
85+
{
86+
label: 'Reload Schema',
87+
accelerator: 'Cmd+R',
88+
click: () => send('Tab', 'ReloadSchema'),
89+
},
8590
],
8691
},
8792
{

packages/graphql-playground-electron/src/renderer/components/App.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ cd ${folderPath}; graphql playground`)
179179
}
180180
}
181181

182+
reloadSchema = () => {
183+
if (this.playground) {
184+
this.playground.reloadSchema()
185+
}
186+
}
187+
182188
componentDidMount() {
183189
ipcRenderer.removeListener('OpenUrl', pushOpenUrl)
184190
ipcRenderer.removeListener('OpenSelectedFile', pushSelectedFile)
@@ -462,6 +468,9 @@ cd ${folderPath}; graphql playground`)
462468
case 'Settings':
463469
this.openSettingsTab()
464470
break
471+
case 'ReloadSchema':
472+
this.reloadSchema()
473+
break
465474
}
466475
}
467476

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export interface State {
8383
selectUserSessionId?: string
8484
codeGenerationPopupOpen: boolean
8585
disableQueryHeader: boolean
86-
autoReloadSchema: boolean
8786
useVim: boolean
8887
userModelName: string
8988

@@ -157,7 +156,6 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
157156
selectUserSessionId: undefined,
158157
codeGenerationPopupOpen: false,
159158
disableQueryHeader: false,
160-
autoReloadSchema: false,
161159
useVim: localStorage.getItem('useVim') === 'true' || false,
162160
shareAllTabs: true,
163161
shareHttpHeaders: true,
@@ -428,14 +426,7 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
428426
}
429427

430428
setRef = (index: number, ref: any) => {
431-
this.graphiqlComponents[index] = ref
432-
}
433-
434-
toggleSchemaReload = () => {
435-
this.setState(state => ({
436-
...state,
437-
autoReloadSchema: !state.autoReloadSchema,
438-
}))
429+
this.graphiqlComponents[index] = ref.getWrappedInstance()
439430
}
440431

441432
handleChangeSettings = (settings: string) => {
@@ -489,6 +480,15 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
489480
this.setValueInSession(session.id, 'hasChanged', false)
490481
}
491482

483+
public reloadSchema = () => {
484+
if (this.graphiqlComponents) {
485+
const editor = this.graphiqlComponents[this.state.selectedSessionIndex]
486+
if (editor && editor.queryEditorComponent) {
487+
editor.reloadSchema()
488+
}
489+
}
490+
}
491+
492492
public openSettingsTab = () => {
493493
const sessionIndex = this.state.sessions.findIndex(s =>
494494
Boolean(s.isSettingsTab),

packages/graphql-playground/src/components/Playground/GraphQLEditor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface Props {
5858
onClickHistory?: () => void
5959
onChangeEndpoint?: (value: string) => void
6060
onClickShare?: () => void
61+
onRef: any
6162
getDefaultFieldNames?: () => any
6263
showCodeGeneration?: boolean
6364
showEndpoints?: boolean
@@ -705,7 +706,7 @@ export class GraphQLEditor extends React.PureComponent<
705706

706707
// Private methods
707708

708-
private reloadSchema = async () => {
709+
public reloadSchema = async () => {
709710
const result = await this.props.schemaFetcher.refetch(
710711
this.props.session.endpoint || this.props.endpoint,
711712
this.convertHeaders(this.props.session.headers),
@@ -1203,7 +1204,7 @@ export class GraphQLEditor extends React.PureComponent<
12031204
}
12041205

12051206
export default withTheme<Props>(
1206-
connect<any, any, Props>(getSessionDocs, { setStacks })(GraphQLEditor),
1207+
connect<any, any, Props>(getSessionDocs, { setStacks }, null, {withRef: true})(GraphQLEditor),
12071208
)
12081209

12091210
// Duck-type promise detection.

packages/graphql-playground/src/components/Playground/GraphQLEditorSession.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default class GraphQLEditorSession extends React.PureComponent<
7979
responses={responses}
8080
disableQueryHeader={disableQueryHeader}
8181
disableResize={false}
82-
ref={this.setRef}
82+
onRef={this.setRef}
8383
useVim={this.props.useVim}
8484
rerenderQuery={false}
8585
disableAnimation={true}

packages/graphql-playground/src/components/Theme/withTheme.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import * as React from 'react'
22
import * as PropTypes from 'prop-types'
33

4-
function withTheme<Props = {}>(Component): React.ComponentClass<Props> {
5-
return class WithTheme extends React.Component<Props, {}> {
4+
export interface ThemeProps {
5+
onRef?: any
6+
}
7+
8+
function withTheme<Props = { onRef?: any}>(Component): React.ComponentClass<Props> {
9+
return class WithTheme extends React.Component<Props & ThemeProps, {}> {
610
static contextTypes = {
711
localTheme: PropTypes.object,
812
}
@@ -27,7 +31,7 @@ function withTheme<Props = {}>(Component): React.ComponentClass<Props> {
2731

2832
render() {
2933
return (
30-
<Component localTheme={this.context.localTheme.theme} {...this.props} />
34+
<Component localTheme={this.context.localTheme.theme} {...this.props} ref={this.props.onRef}/>
3135
)
3236
}
3337
}

0 commit comments

Comments
 (0)