Skip to content

Commit 2272a07

Browse files
committed
graphql-config-extension-graphcool for electron
1 parent f84b2a2 commit 2272a07

File tree

8 files changed

+257
-98
lines changed

8 files changed

+257
-98
lines changed

packages/graphql-playground-electron/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999
"graphcool-styles": "^0.1.31",
100100
"graphcool-tmp-ui": "^0.0.11",
101101
"graphcool-ui": "^0.0.13",
102-
"graphql-config": "^1.0.0",
102+
"graphql-config": "^1.1.0",
103+
"graphql-config-extension-graphcool": "^0.0.1",
103104
"js-yaml": "^3.10.0",
104105
"lodash.merge": "^4.6.0",
105106
"minimist": "^1.2.0",
@@ -138,7 +139,7 @@
138139
"extract-text-webpack-plugin": "^2.0.0-beta.3",
139140
"file-loader": "^0.11.2",
140141
"fork-ts-checker-webpack-plugin": "^0.1.5",
141-
"graphql-playground": "^1.3.5",
142+
"graphql-playground": "^1.3.7-alpha.2",
142143
"happypack": "^3.1.0",
143144
"html-webpack-plugin": "^2.30.1",
144145
"identity-obj-proxy": "^3.0.0",

packages/graphql-playground-electron/src/ElectronApp.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { Icon, $v } from 'graphcool-styles'
55
import * as cx from 'classnames'
66
import { Playground as IPlayground } from 'graphql-playground/lib/components/Playground'
77
import Playground from 'graphql-playground'
8-
import { getGraphQLConfig, findGraphQLConfigFile } from 'graphql-config'
8+
import {
9+
getGraphQLConfig,
10+
findGraphQLConfigFile,
11+
GraphQLConfigData,
12+
} from 'graphql-config'
913
import { createNewWindow } from './utils'
1014
import createStore from './createStore'
1115
import InitialView from './InitialView/InitialView'
@@ -16,6 +20,7 @@ import * as os from 'os'
1620
import * as yaml from 'js-yaml'
1721
import * as findUp from 'find-up'
1822
import * as queryString from 'query-string'
23+
import { patchEndpointsToConfig } from 'graphql-config-extension-graphcool'
1924
// import { PermissionSession } from 'graphql-playground/lib/types'
2025

2126
const { dialog } = remote
@@ -33,8 +38,10 @@ interface State {
3338
platformToken?: string
3439
configString?: string
3540
configPath?: string
41+
3642
folderName?: string
3743
env?: any
44+
config?: GraphQLConfigData
3845
}
3946

4047
const events: any[] = []
@@ -93,7 +100,7 @@ export default class ElectronApp extends React.Component<{}, State> {
93100
this.setState({ endpoint } as State)
94101
}
95102

96-
handleSelectFolder = (folderPath: string) => {
103+
handleSelectFolder = async (folderPath: string) => {
97104
try {
98105
// Get config from folderPath
99106
const configPath = findGraphQLConfigFile(folderPath)
@@ -108,9 +115,15 @@ Then open the graphql config with:
108115
cd ${folderPath}; graphql playground`)
109116
}
110117

118+
const config = await patchEndpointsToConfig(
119+
getGraphQLConfig(path.dirname(configPath)).config,
120+
path.dirname(configPath),
121+
)
122+
111123
this.setState({
112124
configString,
113125
configPath,
126+
config,
114127
folderName: path.basename(folderPath),
115128
} as State)
116129
} catch (error) {
@@ -192,7 +205,7 @@ cd ${folderPath}; graphql playground`)
192205
}
193206
}
194207

195-
handleUrl = (event, url) => {
208+
handleUrl = async (event, url) => {
196209
const cutIndex = url.indexOf('//')
197210
const query = url.slice(cutIndex + 2)
198211
const input = queryString.parse(query)
@@ -209,6 +222,7 @@ cd ${folderPath}; graphql playground`)
209222
let folderName
210223
let configPath
211224
const platformToken = input.platformToken
225+
let config
212226

213227
if (input.cwd) {
214228
configPath = findUp.sync(['.graphqlconfig', '.graphqlconfig.yml'], {
@@ -220,13 +234,18 @@ cd ${folderPath}; graphql playground`)
220234
folderName = configPath
221235
? path.basename(path.dirname(configPath))
222236
: undefined
237+
config = await patchEndpointsToConfig(
238+
getGraphQLConfig(input.cwd).config,
239+
input.cwd,
240+
)
223241
}
224242

225243
this.setState({
226244
configString,
227245
folderName,
228246
env: input.env,
229247
endpoint,
248+
config,
230249
platformToken,
231250
})
232251
}
@@ -403,6 +422,7 @@ cd ${folderPath}; graphql playground`)
403422
openTooltipTheme,
404423
platformToken,
405424
configString,
425+
config,
406426
} = this.state
407427

408428
return (
@@ -447,6 +467,7 @@ cd ${folderPath}; graphql playground`)
447467
isElectron={true}
448468
platformToken={platformToken}
449469
configString={configString}
470+
config={config}
450471
onSaveConfig={this.saveConfig}
451472
canSaveConfig={true}
452473
env={this.state.env}

packages/graphql-playground-electron/src/createStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { compose, createStore } from 'redux'
22
import persistState, { mergePersistedState } from 'redux-localstorage'
33
import filter from 'redux-localstorage-filter'
44
import * as adapter from 'redux-localstorage/lib/adapters/localStorage'
5-
import * as merge from 'lodash/merge'
5+
import { merge } from 'lodash'
66
import combinedReducers from './reducers'
77

88
let localStorage: any = null

0 commit comments

Comments
 (0)