Skip to content

Commit f10ee67

Browse files
authored
Merge pull request #376 from graphcool/reloadschema
Reload schema
2 parents 38cc077 + f327aa8 commit f10ee67

File tree

13 files changed

+51
-28
lines changed

13 files changed

+51
-28
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/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"calculate-size": "^1.1.1",
114114
"classnames": "^2.2.5",
115115
"codemirror": "^5.27.4",
116+
"codemirror-graphql": "^0.6.12",
116117
"cuid": "^1.3.8",
117118
"graphcool-styles": "0.2.4",
118119
"graphcool-tmp-ui": "^0.0.11",
@@ -124,8 +125,10 @@
124125
"keycode": "^2.1.9",
125126
"lodash": "^4.17.4",
126127
"lodash.debounce": "^4.0.8",
128+
"marked": "^0.3.9",
127129
"polished": "^1.9.0",
128130
"postcss-modules": "^0.6.4",
131+
"prop-types": "^15.6.0",
129132
"react": "^16.2.0",
130133
"react-addons-shallow-compare": "^15.6.2",
131134
"react-codemirror": "^1.0.0",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react'
2-
import * as fetch from 'isomorphic-fetch'
32
import { Provider } from 'react-redux'
43
import createStore from '../createStore'
54
import MiddlewareApp from './MiddlewareApp'

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GraphQLEditor } from './Playground/GraphQLEditor'
33
import * as fetch from 'isomorphic-fetch'
44
import { TabBar } from './Playground/TabBar'
55
import { defaultQuery, getDefaultSession } from '../constants'
6-
import { Session } from '../types'
6+
import { Session, ISettings } from '../types'
77
import * as cuid from 'cuid'
88
import * as Immutable from 'seamless-immutable'
99
import PlaygroundStorage from './PlaygroundStorage'
@@ -25,7 +25,6 @@ import { isSharingAuthorization } from './Playground/util/session'
2525
import { SchemaFetcher } from './Playground/SchemaFetcher'
2626
import Settings from './Settings'
2727
import SettingsEditor from './SettingsEditor'
28-
import { ISettings } from '../types'
2928
import { GraphQLConfig } from '../graphqlConfig'
3029
import FileEditor from './FileEditor'
3130

@@ -83,7 +82,6 @@ export interface State {
8382
selectUserSessionId?: string
8483
codeGenerationPopupOpen: boolean
8584
disableQueryHeader: boolean
86-
autoReloadSchema: boolean
8785
useVim: boolean
8886
userModelName: string
8987

@@ -157,7 +155,6 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
157155
selectUserSessionId: undefined,
158156
codeGenerationPopupOpen: false,
159157
disableQueryHeader: false,
160-
autoReloadSchema: false,
161158
useVim: localStorage.getItem('useVim') === 'true' || false,
162159
shareAllTabs: true,
163160
shareHttpHeaders: true,
@@ -428,14 +425,7 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
428425
}
429426

430427
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-
}))
428+
this.graphiqlComponents[index] = ref.getWrappedInstance()
439429
}
440430

441431
handleChangeSettings = (settings: string) => {
@@ -489,6 +479,15 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
489479
this.setValueInSession(session.id, 'hasChanged', false)
490480
}
491481

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

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
*/
88

99
import * as React from 'react'
10-
import * as cx from 'classnames'
11-
import { withTheme, LocalThemeInterface } from '../Theme'
1210
import * as cn from 'classnames'
11+
import { withTheme, LocalThemeInterface } from '../Theme'
1312
import ExecuteButtonOperation from './ExecuteButtonOperation'
1413

1514
export interface Props {
@@ -122,7 +121,7 @@ class ExecuteButton extends React.Component<
122121
}
123122
`}</style>
124123
<div
125-
className={cx('graphcool-execute-button', this.props.localTheme, {
124+
className={cn('graphcool-execute-button', this.props.localTheme, {
126125
running: this.props.isRunning,
127126
})}
128127
onMouseDown={onMouseDown}

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as React from 'react'
2-
import { Session } from '../../types'
2+
import { Session, ISettings } from '../../types'
33
import GraphQLEditor from './GraphQLEditor'
44
import { SchemaFetcher } from './SchemaFetcher'
55
import { SharingProps } from '../Share'
6-
import { ISettings } from '../../types'
76

87
export interface Props {
98
session: Session
@@ -79,7 +78,7 @@ export default class GraphQLEditorSession extends React.PureComponent<
7978
responses={responses}
8079
disableQueryHeader={disableQueryHeader}
8180
disableResize={false}
82-
ref={this.setRef}
81+
onRef={this.setRef}
8382
useVim={this.props.useVim}
8483
rerenderQuery={false}
8584
disableAnimation={true}

packages/graphql-playground/src/components/Playground/SchemaFetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class SchemaFetcher {
1414
}
1515
async fetch(endpoint: string, headers?: any) {
1616
const cachedSchema = this.cache.get(this.hash(endpoint, headers))
17-
return cachedSchema || (await this.fetchSchema(endpoint, headers))
17+
return cachedSchema || this.fetchSchema(endpoint, headers)
1818
}
1919
refetch(endpoint: string, headers: any) {
2020
return this.fetchSchema(endpoint, headers)

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)