Skip to content

Commit 3b277b7

Browse files
committed
fix env var handling
1 parent 670bc03 commit 3b277b7

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

packages/graphql-playground-electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"homepage": "https://github.com/graphcool/graphql-playground",
55
"repository": "graphcool/graphql-playground",
66
"description": "Playground app",
7-
"version": "1.3.7-alpha.3",
7+
"version": "1.3.7-alpha.4",
88
"author": {
99
"name": "Graphcool",
1010
"email": "[email protected]",

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,20 @@ cd ${folderPath}; graphql playground`)
239239
folderName = configPath
240240
? path.basename(path.dirname(configPath))
241241
: undefined
242+
const rawConfig = getGraphQLConfig(input.cwd).config
242243
config = await patchEndpointsToConfig(
243-
resolveEnvsInValues(getGraphQLConfig(input.cwd).config, input.env),
244+
resolveEnvsInValues(rawConfig, input.env),
244245
input.cwd,
245246
input.env,
246247
)
248+
249+
if (!this.configContainsEndpoints(config)) {
250+
const graphcoolNote = configString.includes('graphcool')
251+
? 'Please make sure to add stages to your graphcool.yml'
252+
: ''
253+
alert(`${configPath} does not include any endpoints. ${graphcoolNote}`)
254+
return
255+
}
247256
}
248257

249258
ipcRenderer.send(
@@ -262,6 +271,27 @@ cd ${folderPath}; graphql playground`)
262271
})
263272
}
264273

274+
configContainsEndpoints(config: GraphQLConfigData): boolean {
275+
if (
276+
Object.keys((config.extensions && config.extensions.endpoints) || {})
277+
.length > 0
278+
) {
279+
return true
280+
}
281+
return Object.keys(config.projects).reduce((acc, curr) => {
282+
const project = config.projects[curr]
283+
if (
284+
project.extensions &&
285+
project.extensions.endpoints &&
286+
Object.keys(project.extensions.endpoints).length > 0
287+
) {
288+
return true
289+
}
290+
291+
return acc
292+
}, false)
293+
}
294+
265295
readFileMessage = (event, message) => {
266296
switch (message) {
267297
case 'Open':

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,19 @@ app.on('open-url', (event, url) => {
3737
const cutIndex = url.indexOf('//')
3838
const query = url.slice(cutIndex + 2)
3939
const input = queryString.parse(query)
40-
if (input.env) {
40+
let env
41+
if (input.envPath) {
4142
try {
42-
input.env = JSON.parse(input.env)
43+
env = JSON.parse(fs.readFileSync(input.envPath, 'utf-8'))
44+
fs.unlinkSync(input.envPath)
4345
} catch (e) {
4446
//
4547
}
4648
}
47-
const msg = JSON.stringify(input)
49+
const msg = JSON.stringify({
50+
cwd: input.cwd,
51+
env,
52+
})
4853
forceSend('OpenUrl', msg, input.cwd)
4954
})
5055

@@ -176,12 +181,13 @@ function createWindow() {
176181
windowById.set(newWindow.id, newWindow)
177182

178183
// Emitted when the window is closed.
184+
const id = newWindow.id
179185
newWindow.on('closed', function() {
180186
if (process.platform !== 'darwin' && windows.size === 0) {
181187
app.quit()
182188
}
183189
windows.delete(newWindow)
184-
windowById.delete(newWindow.id)
190+
windowById.delete(id)
185191
windowByPath.forEach((window, cwd) => {
186192
if (window === newWindow) {
187193
windowByPath.delete(cwd)

0 commit comments

Comments
 (0)