Skip to content

Commit 300f250

Browse files
committed
chore(dev): Better local development, added localDev entry point
1 parent d5abec9 commit 300f250

File tree

7 files changed

+90
-68
lines changed

7 files changed

+90
-68
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-playground-middleware-express",
3-
"version": "1.4.6",
3+
"version": "1.4.7",
44
"homepage": "https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware-express",
55
"description": "GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).",
66
"contributors": [
@@ -14,7 +14,7 @@
1414
"files": [
1515
"dist"
1616
],
17-
"playgroundVersion": "1.3.22",
17+
"playgroundVersion": "1.3.23",
1818
"scripts": {
1919
"build": "rimraf dist && tsc",
2020
"prepare": "npm run build"

packages/graphql-playground-react/README.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,51 +41,60 @@ You can easily share your Playgrounds with others by clicking on the "Share" but
4141

4242
> You can also find the announcement blog post [here](https://blog.graph.cool/introducing-graphql-playground-f1e0a018f05d).
4343
44-
4544
## Usage
4645

4746
### Properties
47+
4848
All interfaces, the React component `<Playground />` and all middlewares expose the same set of options:
4949

50-
+ `properties`
51-
+ `endpoint` [`string`] - the GraphQL endpoint url.
52-
+ `subscriptionEndpoint` [`string`] - the GraphQL subscriptions endpoint url.
53-
+ `setTitle` [`boolean`] - reflect the current endpoint in the page title
50+
* `properties`
51+
* `endpoint` [`string`] - the GraphQL endpoint url.
52+
* `subscriptionEndpoint` [`string`] - the GraphQL subscriptions endpoint url.
53+
* `setTitle` [`boolean`] - reflect the current endpoint in the page title
5454

5555
### As React Component
5656

5757
#### Install
58+
5859
```sh
5960
yarn add graphql-playground
6061
```
6162

6263
#### Use
64+
6365
GraphQL Playground provides a React component responsible for rendering the UI and Session management.
6466
There are **3 dependencies** needed in order to run the `graphql-playground` React component.
67+
6568
1. _Open Sans_ and _Source Code Pro_ fonts
6669
2. Including `graphql-playground/playground.css`
6770
3. Rendering the `<Playground />` component
6871

6972
The GraphQL Playground requires **React 16**.
7073

7174
Including Fonts (`1.`)
75+
7276
```html
7377
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Source+Code+Pro:400,700" rel="stylesheet">
7478
```
7579

7680
Including stylesheet and the component (`2., 3.`)
81+
7782
```js
7883
import React from 'react'
7984
import ReactDOM from 'react-dom'
8085
import Playground from 'graphql-playground'
8186
import 'graphql-playground/playground.css'
8287

83-
ReactDOM.render(<Playground endpoint="https://api.graph.cool/simple/v1/swapi" />, document.body)
88+
ReactDOM.render(
89+
<Playground endpoint="https://api.graph.cool/simple/v1/swapi" />,
90+
document.body,
91+
)
8492
```
8593

8694
### As Server Middleware
8795

8896
#### Install
97+
8998
```sh
9099
# Pick the one that matches your server framework
91100
yarn add graphql-playground-middleware-express # for Express or Connect
@@ -98,21 +107,24 @@ yarn add graphql-playground-middleware-lambda
98107

99108
We have a full example for each of the frameworks below:
100109

101-
- **Express:** See [packages/graphql-playground-middleware-express/examples/basic](https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware-express/examples/basic)
110+
* **Express:** See [packages/graphql-playground-middleware-express/examples/basic](https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware-express/examples/basic)
102111

103-
- **Hapi:** See [packages/graphql-playground-middleware/examples/hapi](https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware/examples/hapi)
112+
* **Hapi:** See [packages/graphql-playground-middleware/examples/hapi](https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware/examples/hapi)
104113

105-
- **Koa:** See [packages/graphql-playground-middleware/examples/koa](https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware/examples/koa)
114+
* **Koa:** See [packages/graphql-playground-middleware/examples/koa](https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware/examples/koa)
106115

107-
- **Lambda (as serverless handler):** See [serverless-graphql-apollo](https://github.com/serverless/serverless-graphql-apollo) or a quick example below.
116+
* **Lambda (as serverless handler):** See [serverless-graphql-apollo](https://github.com/serverless/serverless-graphql-apollo) or a quick example below.
108117

109118
### As serverless handler
119+
110120
#### Install
121+
111122
```sh
112123
yarn add graphql-playground-middleware-lambda
113124
```
114125

115126
#### Usage
127+
116128
`handler.js`
117129

118130
```js
@@ -123,17 +135,17 @@ import lambdaPlayground from 'graphql-playground-middleware-lambda'
123135
exports.graphqlHandler = function graphqlHandler(event, context, callback) {
124136
function callbackFilter(error, output) {
125137
// eslint-disable-next-line no-param-reassign
126-
output.headers['Access-Control-Allow-Origin'] = '*';
127-
callback(error, output);
138+
output.headers['Access-Control-Allow-Origin'] = '*'
139+
callback(error, output)
128140
}
129141

130-
const handler = graphqlLambda({ schema: myGraphQLSchema });
131-
return handler(event, context, callbackFilter);
132-
};
142+
const handler = graphqlLambda({ schema: myGraphQLSchema })
143+
return handler(event, context, callbackFilter)
144+
}
133145

134146
exports.playgroundHandler = lambdaPlayground({
135147
endpoint: '/dev/graphql',
136-
});
148+
})
137149
```
138150

139151
`serverless.yml`
@@ -165,9 +177,9 @@ $ cd packages/graphql-playground
165177
$ yarn
166178
$ yarn start
167179
```
168-
Open
169-
[localhost:3000/middleware.html?endpoint=https://api.graph.cool/simple/v1/swapi](http://localhost:3000/middleware.html?endpoint=https://api.graph.cool/simple/v1/swapi) for local development!
170180

181+
Open
182+
[localhost:3000/localDev.html?endpoint=https://api.graph.cool/simple/v1/swapi](http://localhost:3000/localDev.html?endpoint=https://api.graph.cool/simple/v1/swapi) for local development!
171183

172184
<a name="help-and-community" />
173185

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
'use strict';
1+
'use strict'
22

3-
const path = require('path');
4-
const fs = require('fs');
5-
const url = require('url');
3+
const path = require('path')
4+
const fs = require('fs')
5+
const url = require('url')
66

77
// Make sure any symlinks in the project folder are resolved:
88
// https://github.com/facebookincubator/create-react-app/issues/637
9-
const appDirectory = fs.realpathSync(process.cwd());
10-
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
9+
const appDirectory = fs.realpathSync(process.cwd())
10+
const resolveApp = relativePath => path.resolve(appDirectory, relativePath)
1111

12-
const envPublicUrl = process.env.PUBLIC_URL;
12+
const envPublicUrl = process.env.PUBLIC_URL
1313

1414
function ensureSlash(path, needsSlash) {
15-
const hasSlash = path.endsWith('/');
15+
const hasSlash = path.endsWith('/')
1616
if (hasSlash && !needsSlash) {
17-
return path.substr(path, path.length - 1);
17+
return path.substr(path, path.length - 1)
1818
} else if (!hasSlash && needsSlash) {
19-
return `${path}/`;
19+
return `${path}/`
2020
} else {
21-
return path;
21+
return path
2222
}
2323
}
2424

2525
const getPublicUrl = appPackageJson =>
26-
envPublicUrl || require(appPackageJson).homepage;
26+
envPublicUrl || require(appPackageJson).homepage
2727

2828
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
2929
// "public path" at which the app is served.
@@ -32,10 +32,10 @@ const getPublicUrl = appPackageJson =>
3232
// We can't use a relative path in HTML because we don't want to load something
3333
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
3434
function getServedPath(appPackageJson) {
35-
const publicUrl = getPublicUrl(appPackageJson);
35+
const publicUrl = getPublicUrl(appPackageJson)
3636
const servedUrl =
37-
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
38-
return ensureSlash(servedUrl, true);
37+
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/')
38+
return ensureSlash(servedUrl, true)
3939
}
4040

4141
// config after eject: we're in ./config/
@@ -46,6 +46,7 @@ module.exports = {
4646
appHtml: resolveApp('public/index.html'),
4747
appIndexJs: resolveApp('src/index.tsx'),
4848
middlewareIndexJs: resolveApp('src/middlewareIndex.tsx'),
49+
localDevIndexJs: resolveApp('src/localDevIndex.tsx'),
4950
appPackageJson: resolveApp('package.json'),
5051
appSrc: resolveApp('src'),
5152
yarnLockFile: resolveApp('yarn.lock'),
@@ -54,4 +55,4 @@ module.exports = {
5455
appTsConfig: resolveApp('tsconfig.json'),
5556
publicUrl: getPublicUrl(resolveApp('package.json')),
5657
servedPath: getServedPath(resolveApp('package.json')),
57-
};
58+
}

packages/graphql-playground-react/config/webpack.config.dev.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ module.exports = {
4242
require.resolve('react-dev-utils/webpackHotDevClient'),
4343
paths.middlewareIndexJs,
4444
],
45+
localDev: [
46+
require.resolve('./polyfills'),
47+
require.resolve('react-dev-utils/webpackHotDevClient'),
48+
paths.localDevIndexJs,
49+
],
4550
},
4651
output: {
4752
// Next line is not used in dev but WebpackDevServer crashes without it:
@@ -218,15 +223,21 @@ module.exports = {
218223
// Generates an `index.html` file with the <script> injected.
219224
new HtmlWebpackPlugin({
220225
inject: true,
221-
chunks: ["index"],
226+
chunks: ['index'],
222227
template: paths.appHtml,
223228
}),
224229
new HtmlWebpackPlugin({
225230
inject: true,
226-
chunks: ["middleware"],
231+
chunks: ['middleware'],
227232
template: paths.appHtml,
228233
filename: 'middleware.html',
229234
}),
235+
new HtmlWebpackPlugin({
236+
inject: true,
237+
chunks: ['localDev'],
238+
template: paths.appHtml,
239+
filename: 'localDev.html',
240+
}),
230241
// Add module names to factory functions so they appear in browser profiler.
231242
new webpack.NamedModulesPlugin(),
232243
// Makes some environment variables available to the JS code, for example:

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.3.22",
3+
"version": "1.3.23",
44
"main": "./lib/lib.js",
55
"typings": "./lib/lib.d.ts",
66
"description": "GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react'
2+
import * as ReactDOM from 'react-dom'
3+
import MiddlewareApp from './components/MiddlewareApp'
4+
import './styles/graphiql_dark.css'
5+
import './styles/graphiql_light.css'
6+
import './index.css'
7+
import 'graphcool-styles/dist/styles.css'
8+
9+
if (process.env.NODE_ENV !== 'production') {
10+
/* tslint:disable-next-line */
11+
// const { whyDidYouUpdate } = require('why-did-you-update')
12+
// whyDidYouUpdate(React)
13+
}
14+
15+
/* tslint:disable-next-line */
16+
;(window as any)['GraphQLPlayground'] = {
17+
init(element: HTMLElement, options) {
18+
ReactDOM.render(
19+
<MiddlewareApp
20+
setTitle={true}
21+
showNewWorkspace={false}
22+
{...options}
23+
/>,
24+
element,
25+
)
26+
},
27+
}

packages/graphql-playground-react/src/middlewareIndex.tsx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,9 @@ if (process.env.NODE_ENV !== 'production') {
1919
<MiddlewareApp
2020
setTitle={true}
2121
showNewWorkspace={false}
22-
config={config}
2322
{...options}
2423
/>,
2524
element,
2625
)
2726
},
2827
}
29-
30-
const config = {
31-
projects: {
32-
app: {
33-
schemaPath: 'src/schema.graphql',
34-
extensions: {
35-
endpoints: {
36-
default: 'http://localhost:5000',
37-
},
38-
},
39-
},
40-
database: {
41-
schemaPath: 'src/generated/database.graphql',
42-
extensions: {
43-
graphcool: 'graphcool.yml',
44-
endpoints: {
45-
dev: {
46-
url: 'http://localhost:60000/nilan/dev',
47-
headers: {
48-
Authorization:
49-
'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InNlcnZpY2UiOiJuaWxhbkBkZXYiLCJyb2xlcyI6WyJhZG1pbiJdfSwiaWF0IjoxNTE1MTQ1NzI1LCJleHAiOjE1MTU3NTA1MjV9.PP3HPmxqDTS3AM_7J4IjBvWAqhbK9m3Awe4padHLxRs',
50-
},
51-
},
52-
},
53-
},
54-
},
55-
},
56-
}

0 commit comments

Comments
 (0)