Skip to content

Commit 18bd56f

Browse files
committed
updates
1 parent e81286e commit 18bd56f

File tree

9 files changed

+441
-75
lines changed

9 files changed

+441
-75
lines changed

packages/graphql-playground-html/package.json

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"name": "graphql-playground-html",
3-
"version": "1.3.7-alpha.3",
4-
"homepage": "https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-html",
5-
"description": "GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).",
3+
"version": "1.3.7-alpha.8",
4+
"homepage":
5+
"https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-html",
6+
"description":
7+
"GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).",
68
"contributors": [
79
"Tim Suchanek <[email protected]>",
810
"Johannes Schickling <[email protected]>",
@@ -11,19 +13,12 @@
1113
"repository": "http://github.com/graphcool/graphql-playground.git",
1214
"license": "SEE LICENSE IN LICENSE",
1315
"main": "dist/index.js",
14-
"files": [
15-
"dist"
16-
],
16+
"files": ["dist"],
1717
"scripts": {
1818
"build": "tsc",
1919
"prepublishOnly": "npm run build"
2020
},
21-
"keywords": [
22-
"graphql",
23-
"graphiql",
24-
"playground",
25-
"graphcool"
26-
],
21+
"keywords": ["graphql", "graphiql", "playground", "graphcool"],
2722
"devDependencies": {
2823
"@types/node": "^8.0.47",
2924
"typescript": "^2.6.1"

packages/graphql-playground-html/src/render-playground-page.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path'
22
import * as fs from 'fs'
33
import {
4-
getUsedEnvs,
4+
// getUsedEnvs,
55
getGraphQLConfig,
66
findGraphQLConfigFile,
77
resolveEnvsInValues,
@@ -12,10 +12,12 @@ import * as dotenv from 'dotenv'
1212
import getLoadingMarkup from './get-loading-markup'
1313

1414
export interface MiddlewareOptions {
15-
endpoint: string
16-
subscriptionEndpoint?: string
17-
setTitle?: string
18-
folderName?: string
15+
endpoint?: string
16+
subscriptionsEndpoint?: string
17+
htmlTitle?: string
18+
workspaceName?: string
19+
env?: any
20+
useGraphQLConfig?: boolean
1921
}
2022

2123
export interface RenderPageOptions extends MiddlewareOptions {
@@ -25,37 +27,31 @@ export interface RenderPageOptions extends MiddlewareOptions {
2527

2628
const loading = getLoadingMarkup()
2729

28-
let config
29-
let configPath
30-
let configString
31-
let folderName
32-
let env
33-
async function init() {
34-
dotenv.config()
35-
try {
36-
config = getGraphQLConfig().config
37-
config = resolveEnvsInValues(config, process.env)
38-
config = await patchEndpointsToConfig(config, process.cwd(), process.env)
39-
configPath = findGraphQLConfigFile(process.cwd())
40-
configString = fs.readFileSync(configPath, 'utf-8')
41-
folderName = path.basename(process.cwd())
42-
env = getUsedEnvs(config)
43-
} catch (e) {
44-
/* tslint:disable-next-line */
45-
console.error(e)
46-
}
47-
}
30+
dotenv.config()
4831

49-
init()
32+
export async function renderPlaygroundPage(options: RenderPageOptions) {
33+
const env = options.env || {}
5034

51-
export function renderPlaygroundPage(options: RenderPageOptions) {
52-
const extendedOptions = {
35+
const extendedOptions: any = {
5336
...options,
54-
config,
55-
configString,
56-
folderName,
5737
canSaveConfig: false,
58-
env,
38+
}
39+
if (options.htmlTitle) {
40+
extendedOptions.title = options.htmlTitle
41+
}
42+
if (options.useGraphQLConfig) {
43+
let config = getGraphQLConfig().config
44+
config = resolveEnvsInValues(config, env)
45+
config = await patchEndpointsToConfig(config, process.cwd(), env)
46+
const configPath = findGraphQLConfigFile(process.cwd())
47+
const configString = fs.readFileSync(configPath, 'utf-8')
48+
const folderName = path.basename(process.cwd())
49+
extendedOptions.folderName = options.workspaceName || folderName
50+
extendedOptions.config = config
51+
extendedOptions.configString = configString
52+
}
53+
if (options.subscriptionsEndpoint) {
54+
extendedOptions.subscriptionEndpoint = options.subscriptionsEndpoint
5955
}
6056
if (!extendedOptions.endpoint && !extendedOptions.configString) {
6157
/* tslint:disable-next-line */

packages/graphql-playground-middleware-express/examples/graphcool/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const express = require('express')
22
const bodyParser = require('body-parser')
33
const { graphqlExpress } = require('apollo-server-express')
44
const { makeExecutableSchema } = require('graphql-tools')
5-
const expressPlayground = require('../../src/index').default
5+
const expressPlayground = require('graphql-playground-middleware-express').default
66

77
const schema = makeExecutableSchema({
88
typeDefs: `
@@ -19,12 +19,12 @@ const schema = makeExecutableSchema({
1919
},
2020
},
2121
})
22-
const PORT = 4000
22+
const PORT = 4001
2323

2424
const app = express()
2525

2626
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }))
27-
app.get('/playground', expressPlayground({ endpoint: '/graphql' }))
27+
app.get('/playground', expressPlayground({ endpoint: '/graphql', env: process.env, useGraphQLConfig: true}))
2828

2929
app.listen(PORT)
3030

packages/graphql-playground-middleware-express/examples/graphcool/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cors": "^2.8.4",
1616
"express": "^4.16.2",
1717
"graphql": "^0.11.7",
18-
"graphql-playground-middleware-express": "^1.2.1-beta.2",
18+
"graphql-playground-middleware-express": "^1.3.8-beta.3",
1919
"graphql-tools": "^2.7.1"
2020
}
2121
}

0 commit comments

Comments
 (0)