Skip to content

Commit 0b63ba4

Browse files
committed
feat: extract lambada middleware into its own repository
1 parent 8f3a1a8 commit 0b63ba4

File tree

7 files changed

+908
-0
lines changed

7 files changed

+908
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
example/node_modules
6+
example/yarn.lock
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/dist
13+
14+
# misc
15+
.DS_Store
16+
.env
17+
npm-debug.log
18+
.idea
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Graphcool
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "graphql-playground-middleware-lambada",
3+
"version": "1.0.0",
4+
"homepage": "https://github.com/graphcool/graphql-playground/tree/master/packages/graphql-playground-middleware-lambada",
5+
"description": "GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).",
6+
"contributors": [
7+
"Tim Suchanek <[email protected]>",
8+
"Johannes Schickling <[email protected]>",
9+
"Mohammad Rajabifard <[email protected]>"
10+
],
11+
"repository": "http://github.com/graphcool/graphql-playground.git",
12+
"license": "SEE LICENSE IN LICENSE",
13+
"main": "dist/index.js",
14+
"files": [
15+
"dist"
16+
],
17+
"scripts": {
18+
"build": "tsc",
19+
"prepublishOnly": "npm run build"
20+
},
21+
"keywords": [
22+
"graphql",
23+
"graphiql",
24+
"playground",
25+
"graphcool",
26+
"lambada"
27+
],
28+
"peerDependencies": {
29+
"aws-lambda": "^0.1.2"
30+
},
31+
"devDependencies": {
32+
"@types/node": "^8.0.47",
33+
"typescript": "^2.6.1"
34+
},
35+
"typings": "dist/index.d.ts",
36+
"typescript": {
37+
"definition": "dist/index.d.ts"
38+
}
39+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as lambda from 'aws-lambda'
2+
import renderPlaygroundPage, {
3+
MiddlewareOptions,
4+
} from './render-playground-page'
5+
6+
/* tslint:disable-next-line */
7+
const { version } = require('../package.json')
8+
9+
export default function lambdaPlayground(options: MiddlewareOptions) {
10+
return (event, lambdaContext: lambda.Context, callback: lambda.Callback) => {
11+
const middlewareOptions: MiddlewareOptions = {
12+
...options,
13+
version,
14+
}
15+
const body = renderPlaygroundPage(middlewareOptions)
16+
callback(null, {
17+
statusCode: 200,
18+
headers: {
19+
'Content-Type': 'text/html',
20+
},
21+
body,
22+
})
23+
}
24+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
export interface MiddlewareOptions {
2+
endpoint: string
3+
subscriptionEndpoint?: string
4+
version: string
5+
}
6+
7+
export default function renderPlaygroundPage(options: MiddlewareOptions) {
8+
return `
9+
<!DOCTYPE html>
10+
<html>
11+
<head>
12+
<meta charset=utf-8 />
13+
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
14+
<title>GraphQL Playground</title>
15+
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/graphql-playground@${options.version}/build/static/css/index.css" />
16+
<link rel="shortcut icon" href="//cdn.jsdelivr.net/npm/graphql-playground@${options.version}/build/favicon.png" />
17+
<script src="//cdn.jsdelivr.net/npm/graphql-playground@${options.version}/build/static/js/middleware.js"></script>
18+
</head>
19+
<body>
20+
<div id="root">
21+
<style>
22+
body {
23+
background-color: rgb(23,42,58);
24+
font-family: Open Sans,sans-serif;
25+
height: 90vh;
26+
}
27+
#root {
28+
height: 100%;
29+
width: 100%;
30+
display: flex;
31+
align-items: center;
32+
justify-content: center;
33+
}
34+
.loading {
35+
font-size: 32px;
36+
font-weight: 200;
37+
color: rgba(255,255,255,.6);
38+
margin-left: 20px;
39+
}
40+
img {
41+
width: 78px;
42+
height: 78px;
43+
}
44+
.title {
45+
font-weight: 400;
46+
}
47+
</style>
48+
<img src='http://cdn.jsdelivr.net/npm/graphql-playground/build/logo.png' alt=''>
49+
<div class="loading">
50+
Loading <span class="title">GraphQL Playground</span>
51+
</div>
52+
</div>
53+
<script>
54+
window.addEventListener('load', function(event) {
55+
GraphQLPlayground.init(document.getElementById('root'), ${JSON.stringify(
56+
options,
57+
null,
58+
2,
59+
)})
60+
})
61+
</script>
62+
</body>
63+
</html>
64+
`
65+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"target": "es5",
5+
"lib": ["esnext", "dom"],
6+
"sourceMap": true,
7+
"rootDir": "src",
8+
"forceConsistentCasingInFileNames": true,
9+
"noImplicitReturns": true,
10+
"noImplicitThis": true,
11+
"noImplicitAny": false,
12+
"strictNullChecks": true,
13+
"suppressImplicitAnyIndexErrors": true,
14+
"noUnusedLocals": true,
15+
"declaration": true
16+
}
17+
}

0 commit comments

Comments
 (0)