Skip to content

Commit

Permalink
Merge pull request #376 from graphcool/reloadschema
Browse files Browse the repository at this point in the history
Reload schema
  • Loading branch information
schickling authored Jan 3, 2018
2 parents 38cc077 + f327aa8 commit f10ee67
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 28 deletions.
5 changes: 5 additions & 0 deletions packages/graphql-playground-electron/src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const buildTemplate = (
accelerator: 'Cmd+S',
click: () => send('File', 'Save'),
},
{
label: 'Reload Schema',
accelerator: 'Cmd+R',
click: () => send('Tab', 'ReloadSchema'),
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ cd ${folderPath}; graphql playground`)
}
}

reloadSchema = () => {
if (this.playground) {
this.playground.reloadSchema()
}
}

componentDidMount() {
ipcRenderer.removeListener('OpenUrl', pushOpenUrl)
ipcRenderer.removeListener('OpenSelectedFile', pushSelectedFile)
Expand Down Expand Up @@ -462,6 +468,9 @@ cd ${folderPath}; graphql playground`)
case 'Settings':
this.openSettingsTab()
break
case 'ReloadSchema':
this.reloadSchema()
break
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/graphql-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"calculate-size": "^1.1.1",
"classnames": "^2.2.5",
"codemirror": "^5.27.4",
"codemirror-graphql": "^0.6.12",
"cuid": "^1.3.8",
"graphcool-styles": "0.2.4",
"graphcool-tmp-ui": "^0.0.11",
Expand All @@ -124,8 +125,10 @@
"keycode": "^2.1.9",
"lodash": "^4.17.4",
"lodash.debounce": "^4.0.8",
"marked": "^0.3.9",
"polished": "^1.9.0",
"postcss-modules": "^0.6.4",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-addons-shallow-compare": "^15.6.2",
"react-codemirror": "^1.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/graphql-playground/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react'
import * as fetch from 'isomorphic-fetch'
import { Provider } from 'react-redux'
import createStore from '../createStore'
import MiddlewareApp from './MiddlewareApp'
Expand Down
23 changes: 11 additions & 12 deletions packages/graphql-playground/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GraphQLEditor } from './Playground/GraphQLEditor'
import * as fetch from 'isomorphic-fetch'
import { TabBar } from './Playground/TabBar'
import { defaultQuery, getDefaultSession } from '../constants'
import { Session } from '../types'
import { Session, ISettings } from '../types'
import * as cuid from 'cuid'
import * as Immutable from 'seamless-immutable'
import PlaygroundStorage from './PlaygroundStorage'
Expand All @@ -25,7 +25,6 @@ import { isSharingAuthorization } from './Playground/util/session'
import { SchemaFetcher } from './Playground/SchemaFetcher'
import Settings from './Settings'
import SettingsEditor from './SettingsEditor'
import { ISettings } from '../types'
import { GraphQLConfig } from '../graphqlConfig'
import FileEditor from './FileEditor'

Expand Down Expand Up @@ -83,7 +82,6 @@ export interface State {
selectUserSessionId?: string
codeGenerationPopupOpen: boolean
disableQueryHeader: boolean
autoReloadSchema: boolean
useVim: boolean
userModelName: string

Expand Down Expand Up @@ -157,7 +155,6 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
selectUserSessionId: undefined,
codeGenerationPopupOpen: false,
disableQueryHeader: false,
autoReloadSchema: false,
useVim: localStorage.getItem('useVim') === 'true' || false,
shareAllTabs: true,
shareHttpHeaders: true,
Expand Down Expand Up @@ -428,14 +425,7 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
}

setRef = (index: number, ref: any) => {
this.graphiqlComponents[index] = ref
}

toggleSchemaReload = () => {
this.setState(state => ({
...state,
autoReloadSchema: !state.autoReloadSchema,
}))
this.graphiqlComponents[index] = ref.getWrappedInstance()
}

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

public reloadSchema = () => {
if (this.graphiqlComponents) {
const editor = this.graphiqlComponents[this.state.selectedSessionIndex]
if (editor && editor.queryEditorComponent) {
editor.reloadSchema()
}
}
}

public openSettingsTab = () => {
const sessionIndex = this.state.sessions.findIndex(s =>
Boolean(s.isSettingsTab),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
*/

import * as React from 'react'
import * as cx from 'classnames'
import { withTheme, LocalThemeInterface } from '../Theme'
import * as cn from 'classnames'
import { withTheme, LocalThemeInterface } from '../Theme'
import ExecuteButtonOperation from './ExecuteButtonOperation'

export interface Props {
Expand Down Expand Up @@ -122,7 +121,7 @@ class ExecuteButton extends React.Component<
}
`}</style>
<div
className={cx('graphcool-execute-button', this.props.localTheme, {
className={cn('graphcool-execute-button', this.props.localTheme, {
running: this.props.isRunning,
})}
onMouseDown={onMouseDown}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface Props {
onClickHistory?: () => void
onChangeEndpoint?: (value: string) => void
onClickShare?: () => void
onRef: any
getDefaultFieldNames?: () => any
showCodeGeneration?: boolean
showEndpoints?: boolean
Expand Down Expand Up @@ -705,7 +706,7 @@ export class GraphQLEditor extends React.PureComponent<

// Private methods

private reloadSchema = async () => {
public reloadSchema = async () => {
const result = await this.props.schemaFetcher.refetch(
this.props.session.endpoint || this.props.endpoint,
this.convertHeaders(this.props.session.headers),
Expand Down Expand Up @@ -1203,7 +1204,7 @@ export class GraphQLEditor extends React.PureComponent<
}

export default withTheme<Props>(
connect<any, any, Props>(getSessionDocs, { setStacks })(GraphQLEditor),
connect<any, any, Props>(getSessionDocs, { setStacks }, null, {withRef: true})(GraphQLEditor),
)

// Duck-type promise detection.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from 'react'
import { Session } from '../../types'
import { Session, ISettings } from '../../types'
import GraphQLEditor from './GraphQLEditor'
import { SchemaFetcher } from './SchemaFetcher'
import { SharingProps } from '../Share'
import { ISettings } from '../../types'

export interface Props {
session: Session
Expand Down Expand Up @@ -79,7 +78,7 @@ export default class GraphQLEditorSession extends React.PureComponent<
responses={responses}
disableQueryHeader={disableQueryHeader}
disableResize={false}
ref={this.setRef}
onRef={this.setRef}
useVim={this.props.useVim}
rerenderQuery={false}
disableAnimation={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class SchemaFetcher {
}
async fetch(endpoint: string, headers?: any) {
const cachedSchema = this.cache.get(this.hash(endpoint, headers))
return cachedSchema || (await this.fetchSchema(endpoint, headers))
return cachedSchema || this.fetchSchema(endpoint, headers)
}
refetch(endpoint: string, headers: any) {
return this.fetchSchema(endpoint, headers)
Expand Down
10 changes: 7 additions & 3 deletions packages/graphql-playground/src/components/Theme/withTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as React from 'react'
import * as PropTypes from 'prop-types'

function withTheme<Props = {}>(Component): React.ComponentClass<Props> {
return class WithTheme extends React.Component<Props, {}> {
export interface ThemeProps {
onRef?: any
}

function withTheme<Props = { onRef?: any}>(Component): React.ComponentClass<Props> {
return class WithTheme extends React.Component<Props & ThemeProps, {}> {
static contextTypes = {
localTheme: PropTypes.object,
}
Expand All @@ -27,7 +31,7 @@ function withTheme<Props = {}>(Component): React.ComponentClass<Props> {

render() {
return (
<Component localTheme={this.context.localTheme.theme} {...this.props} />
<Component localTheme={this.context.localTheme.theme} {...this.props} ref={this.props.onRef}/>
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-playground/src/styled/styled.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as styledComponents from 'styled-components'
import { ThemedStyledComponentsModule } from 'styled-components'
import { ThemedStyledComponentsModule } from 'styled-components' // tslint:disable-line

import { ThemeInterface, theme } from './theme'

Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-playground/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"tslint-graphcool-frontend"
],
"rules": {
"forin": false
"forin": false,
"no-submodule-imports": false
}
}
6 changes: 5 additions & 1 deletion packages/graphql-playground/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"

codemirror-graphql@^0.6.11:
codemirror-graphql@^0.6.11, codemirror-graphql@^0.6.12:
version "0.6.12"
resolved "https://registry.yarnpkg.com/codemirror-graphql/-/codemirror-graphql-0.6.12.tgz#91a273fe5188857524a30221d06e645b4ca41f00"
dependencies:
Expand Down Expand Up @@ -4503,6 +4503,10 @@ [email protected]:
version "0.3.6"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.6.tgz#b2c6c618fccece4ef86c4fc6cb8a7cbf5aeda8d7"

marked@^0.3.9:
version "0.3.9"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.9.tgz#54ce6a57e720c3ac6098374ec625fcbcc97ff290"

math-expression-evaluator@^1.2.14:
version "1.2.17"
resolved "https://registry.yarnpkg.com/math-expression-evaluator/-/math-expression-evaluator-1.2.17.tgz#de819fdbcd84dccd8fae59c6aeb79615b9d266ac"
Expand Down

0 comments on commit f10ee67

Please sign in to comment.