Skip to content

Commit 0356557

Browse files
committed
fix(settings): Expose settings programmatically, update deps
1 parent 9ab9d48 commit 0356557

File tree

9 files changed

+76
-55
lines changed

9 files changed

+76
-55
lines changed

packages/graphql-playground-electron/webpack.config.build.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const path = require('path')
55
const config = require('./webpack.config')
66
const HappyPack = require('happypack')
77
const os = require('os')
8+
const fs = require('fs')
89
const UglifyJSParallelPlugin = require('webpack-uglify-parallel')
9-
const { renderPlaygroundPage } = require('graphql-playground-html');
10+
const { renderPlaygroundPage } = require('graphql-playground-html')
1011

11-
const appEntrypoint = 'src/renderer/index.html'
12+
const appEntrypoint = 'src/renderer/index.html'
1213

1314
// Create the playground entry point if it doesn't exist
14-
if(!fs.existsSync(appEntrypoint)) {
15-
fs.writeFileSync(appEntrypoint, renderPlaygroundPage({env: 'react'}));
15+
if (!fs.existsSync(appEntrypoint)) {
16+
fs.writeFileSync(appEntrypoint, renderPlaygroundPage({ env: 'react' }))
1617
}
1718

1819
module.exports = {
@@ -27,7 +28,7 @@ module.exports = {
2728
sourceMapFilename: '[file].map',
2829
publicPath: './',
2930
},
30-
node: {
31+
node: {
3132
__dirname: false,
3233
__filename: false,
3334
},
@@ -91,7 +92,7 @@ module.exports = {
9192
plugins: [
9293
new webpack.DefinePlugin({
9394
'process.env': {
94-
NODE_ENV: JSON.stringify('production')
95+
NODE_ENV: JSON.stringify('production'),
9596
},
9697
__EXAMPLE_ADDR__: '"https://dynamic-resources.graph.cool"',
9798
}),
@@ -111,7 +112,10 @@ module.exports = {
111112
mangle: false,
112113
}), */
113114
// https://github.com/graphql/graphql-language-service/issues/111
114-
new webpack.ContextReplacementPlugin(/graphql-language-service-interface[\/\\]dist/, /\.js$/),
115+
new webpack.ContextReplacementPlugin(
116+
/graphql-language-service-interface[\/\\]dist/,
117+
/\.js$/,
118+
),
115119
new webpack.NormalModuleReplacementPlugin(/\/iconv-loader$/, 'node-noop'),
116120
new webpack.optimize.CommonsChunkPlugin('vendor'),
117121
new webpack.optimize.ModuleConcatenationPlugin(),

packages/graphql-playground-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-playground-react",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"main": "./lib/lib.js",
55
"typings": "./lib/lib.d.ts",
66
"description": "GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).",

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export default class App extends React.Component<Props, State> {
5454

5555
// DOM side-effect:
5656
// #loading-wrapper is a hardcoded DOM element in the HTML entrypoint
57-
const loadingWrapper = document.getElementById('loading-wrapper');
57+
const loadingWrapper = document.getElementById('loading-wrapper')
5858

5959
if (loadingWrapper) {
60-
loadingWrapper.classList.remove('fadeOut');
60+
loadingWrapper.classList.remove('fadeOut')
6161
}
6262

6363
fetch('https://api.graph.cool/simple/v1/cj81hi46q03c30196uxaswrz2', {
@@ -80,7 +80,7 @@ export default class App extends React.Component<Props, State> {
8080
.then(res => res.json())
8181
.then(res => {
8282
if (loadingWrapper) {
83-
loadingWrapper.classList.add('fadeOut');
83+
loadingWrapper.classList.add('fadeOut')
8484
}
8585

8686
if (!res.data || res.data.session === null) {
@@ -118,9 +118,8 @@ export default class App extends React.Component<Props, State> {
118118
}
119119
`}</style>
120120

121-
{this.state.loading ? (
122-
null
123-
) : !this.state.endpoint || this.state.endpoint.length === 0 ? (
121+
{this.state.loading ? null : !this.state.endpoint ||
122+
this.state.endpoint.length === 0 ? (
124123
<ThemeProvider theme={styledTheme}>
125124
<EndpointPopup
126125
onRequestClose={this.handleChangeEndpoint}
@@ -132,12 +131,12 @@ export default class App extends React.Component<Props, State> {
132131
/>
133132
</ThemeProvider>
134133
) : (
135-
<MiddlewareApp
136-
endpoint={endpoint}
137-
subscriptionEndpoint={subscriptionEndpoint}
138-
session={this.state.session}
139-
/>
140-
)}
134+
<MiddlewareApp
135+
endpoint={endpoint}
136+
subscriptionEndpoint={subscriptionEndpoint}
137+
session={this.state.session}
138+
/>
139+
)}
141140
</div>
142141
</Provider>
143142
)

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import * as fetch from 'isomorphic-fetch'
77
import { GraphQLConfig } from '../graphqlConfig'
88
import * as yaml from 'js-yaml'
99
import ProjectsSideNav from './ProjectsSideNav'
10-
import { styled, ThemeProvider, theme as styledTheme, keyframes } from '../styled'
10+
import {
11+
styled,
12+
ThemeProvider,
13+
theme as styledTheme,
14+
keyframes,
15+
} from '../styled'
1116
import OldThemeProvider from './Theme/ThemeProvider'
1217
import { getActiveEndpoints } from './util'
1318
import { ISettings } from '../types'
@@ -75,7 +80,7 @@ export default class MiddlewareApp extends React.Component<Props, State> {
7580
playground: IPlayground
7681
constructor(props: Props) {
7782
super(props)
78-
; (global as any).m = this
83+
;(global as any).m = this
7984

8085
let settingsString = localStorage.getItem('settings') || defaultSettings
8186
settingsString = this.migrateSettingsString(settingsString)
@@ -116,7 +121,7 @@ export default class MiddlewareApp extends React.Component<Props, State> {
116121
undefined,
117122
subscriptionEndpoint,
118123
settingsString,
119-
settings: this.getSettings(settingsString),
124+
settings: this.props.settings || this.getSettings(settingsString),
120125
configIsYaml,
121126
configString: props.configString,
122127
activeEnv,
@@ -129,7 +134,7 @@ export default class MiddlewareApp extends React.Component<Props, State> {
129134
if (endpoint.includes('api.graph.cool')) {
130135
return `wss://subscriptions.graph.cool/v1/${
131136
endpoint.split('/').slice(-1)[0]
132-
}`
137+
}`
133138
}
134139

135140
return endpoint
@@ -530,7 +535,7 @@ const appearIn = keyframes`
530535
opacity: 1;
531536
transform: translateY(0);
532537
}
533-
`;
538+
`
534539

535540
const App = styled.div`
536541
display: flex;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
132132
}
133133

134134
const sessions = this.initSessions(props)
135-
this.schemaFetcher = new SchemaFetcher()
135+
this.schemaFetcher = new SchemaFetcher(this.props.settings)
136136

137137
const selectedSessionIndex =
138138
parseInt(this.storage.getItem('selectedSessionIndex'), 10) || 0

packages/graphql-playground-react/src/components/Playground/DocExplorer/GraphDocs.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,9 @@ class GraphDocs extends React.Component<
254254
)
255255
}
256256

257-
public showDocFromType = (type) => {
258-
this.props.toggleDocs(this.props.sessionId, true);
259-
this.props.addStack(
260-
this.props.sessionId,
261-
type,
262-
0,
263-
0
264-
)
257+
public showDocFromType = type => {
258+
this.props.toggleDocs(this.props.sessionId, true)
259+
this.props.addStack(this.props.sessionId, type, 0, 0)
265260
}
266261

267262
private setDocExplorerRef = ref => {
@@ -437,5 +432,5 @@ export default connect<StateFromProps, DispatchFromProps, Props>(
437432
getSessionDocs,
438433
mapDispatchToProps,
439434
null,
440-
{ withRef: true }
435+
{ withRef: true },
441436
)(GraphDocs)

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class QueryEditor extends React.Component<Props, {}> {
7171
require('codemirror/addon/dialog/dialog')
7272
require('codemirror/addon/lint/lint')
7373
require('codemirror/keymap/sublime')
74+
require('codemirror/keymap/vim')
7475
require('codemirror-graphql/hint')
7576
require('codemirror-graphql/lint')
7677
require('codemirror-graphql/info')
@@ -168,20 +169,6 @@ export class QueryEditor extends React.Component<Props, {}> {
168169
this.editor.options.info.schema = this.props.schema
169170
this.editor.options.jump.schema = this.props.schema
170171
CodeMirror.signal(this.editor, 'change', this.editor)
171-
if (this.props.schema) {
172-
const oldGetType = this.editor.options.hintOptions.schema.getType
173-
/**
174-
* DANGER! THIS IS AN EXTREME HACK. As soon, as codemirror-graphql doesn't use getType in .hint anymore
175-
* this can be removed.
176-
*/
177-
this.editor.options.hintOptions.schema.getType = type => {
178-
const result = oldGetType.call(
179-
this.editor.options.hintOptions.schema,
180-
type,
181-
)
182-
return result || type
183-
}
184-
}
185172
}
186173
if (
187174
this.props.value !== prevProps.value &&
@@ -190,10 +177,6 @@ export class QueryEditor extends React.Component<Props, {}> {
190177
this.cachedValue = this.props.value
191178
this.editor.setValue(this.props.value)
192179
}
193-
if (this.props.useVim !== prevProps.useVim) {
194-
this.editor.options.keyMap = this.props.useVim ? 'vim' : 'sublime'
195-
CodeMirror.signal(this.editor, 'change', this.editor)
196-
}
197180
if (this.props.readOnly !== prevProps.readOnly) {
198181
this.editor.options.readOnly = this.props.readOnly
199182
CodeMirror.signal(this.editor, 'change', this.editor)

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { GraphQLSchema, introspectionQuery, buildClientSchema } from 'graphql'
22
import * as stringify from 'json-stable-stringify'
33
import { NoSchemaError } from './util/NoSchemaError'
4+
import { ISettings } from '../../types'
45

56
export interface TracingSchemaTuple {
67
schema: GraphQLSchema
@@ -9,7 +10,9 @@ export interface TracingSchemaTuple {
910

1011
export class SchemaFetcher {
1112
cache: Map<string, TracingSchemaTuple>
12-
constructor() {
13+
settings: ISettings
14+
constructor(settings: ISettings) {
15+
this.settings = settings
1316
this.cache = new Map()
1417
}
1518
async fetch(endpoint: string, headers?: any) {
@@ -28,7 +31,7 @@ export class SchemaFetcher {
2831
): Promise<{ schema: GraphQLSchema; tracingSupported: boolean } | null> {
2932
const response = await fetch(endpoint, {
3033
method: 'post',
31-
credentials: 'include',
34+
credentials: this.settings['request.credentials'],
3235
headers: {
3336
'Content-Type': 'application/json',
3437
'X-Apollo-Tracing': '1',
@@ -48,6 +51,15 @@ export class SchemaFetcher {
4851
}
4952

5053
const schema = buildClientSchema(schemaData.data)
54+
/**
55+
* DANGER! THIS IS AN EXTREME HACK. As soon, as codemirror-graphql doesn't use getType in .hint anymore
56+
* this can be removed.
57+
*/
58+
const oldGetType = schema.getType
59+
schema.getType = type => {
60+
const getTypeResult = oldGetType.call(schema, type)
61+
return getTypeResult || type
62+
}
5163
const tracingSupported =
5264
schemaData.extensions && Boolean(schemaData.extensions.tracing)
5365
const result = {

packages/graphql-playground-react/yarn.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,6 +3361,16 @@ [email protected]:
33613361
minimatch "^3.0.4"
33623362
rimraf "^2.6.2"
33633363

3364+
3365+
version "1.1.7"
3366+
resolved "https://registry.yarnpkg.com/graphql-config/-/graphql-config-1.1.7.tgz#546c443d3ad877ceb8e13f40fbc8937af0d35dbe"
3367+
dependencies:
3368+
graphql "^0.12.3"
3369+
graphql-import "^0.4.0"
3370+
graphql-request "^1.4.0"
3371+
js-yaml "^3.10.0"
3372+
minimatch "^3.0.4"
3373+
33643374
graphql-import@^0.1.7:
33653375
version "0.1.9"
33663376
resolved "https://registry.yarnpkg.com/graphql-import/-/graphql-import-0.1.9.tgz#9161f4f7ea92337b60fd40e22e64d3a68c212729"
@@ -3370,6 +3380,13 @@ graphql-import@^0.1.7:
33703380
graphql "^0.12.3"
33713381
lodash "^4.17.4"
33723382

3383+
graphql-import@^0.4.0:
3384+
version "0.4.2"
3385+
resolved "https://registry.yarnpkg.com/graphql-import/-/graphql-import-0.4.2.tgz#e4925e838cf41d69d81d3879788ef8ee77532977"
3386+
dependencies:
3387+
graphql "^0.12.3"
3388+
lodash "^4.17.4"
3389+
33733390
graphql-language-service-interface@^1.0.16:
33743391
version "1.0.18"
33753392
resolved "https://registry.yarnpkg.com/graphql-language-service-interface/-/graphql-language-service-interface-1.0.18.tgz#c0fc1ef72c6f6f4bf9042bd7a8a8a66e0772caa8"
@@ -3409,6 +3426,12 @@ graphql-language-service-utils@^1.0.18:
34093426
graphql-config "1.1.4"
34103427
graphql-language-service-types "^1.0.18"
34113428

3429+
graphql-playground-html@^1.5.2:
3430+
version "1.5.2"
3431+
resolved "https://registry.yarnpkg.com/graphql-playground-html/-/graphql-playground-html-1.5.2.tgz#ccd97ac1960cfb1872b314bafb1957e7a6df7984"
3432+
dependencies:
3433+
graphql-config "1.1.7"
3434+
34123435
graphql-request@^1.4.0:
34133436
version "1.4.1"
34143437
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-1.4.1.tgz#0772743cfac8dfdd4d69d36106a96c9bdd191ce8"

0 commit comments

Comments
 (0)