Skip to content

Commit c7efc81

Browse files
committed
add lambda example
1 parent d5da54b commit c7efc81

File tree

5 files changed

+202
-0
lines changed

5 files changed

+202
-0
lines changed

packages/graphql-playground-middleware-lambda/examples/basic/.gitignore

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// or using require()
2+
const {makeExecutableSchema} = require('graphql-tools')
3+
const lambdaPlayground = require('graphql-playground-middleware-lambda').default
4+
const {graphqlLambda} = require('apollo-server-lambda')
5+
6+
const typeDefs = `
7+
type Post {
8+
id: ID!
9+
title: String
10+
}
11+
12+
type Query {
13+
posts: [Post]
14+
}
15+
schema {
16+
query: Query
17+
}
18+
`;
19+
20+
const resolvers = {
21+
Query: {
22+
posts() {
23+
return [{id: "1", title: "Awesome Post"}];
24+
},
25+
},
26+
};
27+
28+
exports.graphqlHandler = function graphqlHandler(event, context, callback) {
29+
function callbackFilter(error, output) {
30+
// eslint-disable-next-line no-param-reassign
31+
output.headers['Access-Control-Allow-Origin'] = '*';
32+
callback(error, output);
33+
}
34+
35+
const myGraphQLSchema = makeExecutableSchema({typeDefs, resolvers})
36+
37+
const handler = graphqlLambda({ schema: myGraphQLSchema });
38+
return handler(event, context, callbackFilter);
39+
};
40+
41+
exports.playgroundHandler = lambdaPlayground({
42+
endpoint: '/dev/graphql',
43+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"apollo-server-lambda": "^1.2.0",
8+
"graphql": "^0.11.7",
9+
"graphql-playground-middleware-lambda": "^1.3.1",
10+
"graphql-tools": "^2.11.0"
11+
}
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
service: playground-test
2+
3+
provider:
4+
name: aws
5+
runtime: nodejs6.10
6+
7+
8+
functions:
9+
graphql:
10+
handler: handler.graphqlHandler
11+
events:
12+
- http:
13+
path: graphql
14+
method: post
15+
cors: true
16+
playground:
17+
handler: handler.playgroundHandler
18+
events:
19+
- http:
20+
path: playground
21+
method: get
22+
cors: true
23+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
apollo-cache-control@^0.0.x:
6+
version "0.0.7"
7+
resolved "https://registry.yarnpkg.com/apollo-cache-control/-/apollo-cache-control-0.0.7.tgz#ffef56413a429a1ce204be5b78d248c4fe3b67ac"
8+
dependencies:
9+
graphql-extensions "^0.0.x"
10+
11+
apollo-server-core@^1.2.0:
12+
version "1.2.0"
13+
resolved "https://registry.yarnpkg.com/apollo-server-core/-/apollo-server-core-1.2.0.tgz#e851c47444991b6f89f88529237076b83e01e8ee"
14+
dependencies:
15+
apollo-cache-control "^0.0.x"
16+
apollo-tracing "^0.1.0"
17+
graphql-extensions "^0.0.x"
18+
19+
apollo-server-lambda@^1.2.0:
20+
version "1.2.0"
21+
resolved "https://registry.yarnpkg.com/apollo-server-lambda/-/apollo-server-lambda-1.2.0.tgz#cdcc8901a85bcc08be35836e1d835e26c8ad2bc1"
22+
dependencies:
23+
apollo-server-core "^1.2.0"
24+
apollo-server-module-graphiql "^1.2.0"
25+
26+
apollo-server-module-graphiql@^1.2.0:
27+
version "1.2.0"
28+
resolved "https://registry.yarnpkg.com/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.2.0.tgz#899d84f3b747795dbbfc8354aa51622ef038151c"
29+
30+
apollo-tracing@^0.1.0:
31+
version "0.1.1"
32+
resolved "https://registry.yarnpkg.com/apollo-tracing/-/apollo-tracing-0.1.1.tgz#7a5707543fc102f81cda7ba45b98331a82a6750b"
33+
dependencies:
34+
graphql-extensions "^0.0.x"
35+
36+
apollo-utilities@^1.0.1:
37+
version "1.0.3"
38+
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.0.3.tgz#bf435277609850dd442cf1d5c2e8bc6655eaa943"
39+
40+
core-js@^2.5.1:
41+
version "2.5.1"
42+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.1.tgz#ae6874dc66937789b80754ff5428df66819ca50b"
43+
44+
deprecated-decorator@^0.1.6:
45+
version "0.1.6"
46+
resolved "https://registry.yarnpkg.com/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz#00966317b7a12fe92f3cc831f7583af329b86c37"
47+
48+
find-up@^2.1.0:
49+
version "2.1.0"
50+
resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"
51+
dependencies:
52+
locate-path "^2.0.0"
53+
54+
graphql-extensions@^0.0.x:
55+
version "0.0.5"
56+
resolved "https://registry.yarnpkg.com/graphql-extensions/-/graphql-extensions-0.0.5.tgz#63bc4a3fd31aab12bfadf783cbc038a9a6937cf0"
57+
dependencies:
58+
core-js "^2.5.1"
59+
source-map-support "^0.5.0"
60+
61+
graphql-playground-middleware-lambda@^1.3.1:
62+
version "1.3.1"
63+
resolved "https://registry.yarnpkg.com/graphql-playground-middleware-lambda/-/graphql-playground-middleware-lambda-1.3.1.tgz#265c5bc1965ca1cfd0613b00264ede7770e85d92"
64+
dependencies:
65+
graphql-playground-middleware "^1.2.1-beta.6"
66+
67+
graphql-playground-middleware@^1.2.1-beta.6:
68+
version "1.2.1-beta.6"
69+
resolved "https://registry.yarnpkg.com/graphql-playground-middleware/-/graphql-playground-middleware-1.2.1-beta.6.tgz#b302bda88d28fae716d127a483659c8e70a18776"
70+
dependencies:
71+
find-up "^2.1.0"
72+
73+
graphql-tools@^2.11.0:
74+
version "2.11.0"
75+
resolved "https://registry.yarnpkg.com/graphql-tools/-/graphql-tools-2.11.0.tgz#be86d14acfe4ca9411967c6b54bac2eedc0dbb72"
76+
dependencies:
77+
apollo-utilities "^1.0.1"
78+
deprecated-decorator "^0.1.6"
79+
uuid "^3.1.0"
80+
81+
graphql@^0.11.7:
82+
version "0.11.7"
83+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.11.7.tgz#e5abaa9cb7b7cccb84e9f0836bf4370d268750c6"
84+
dependencies:
85+
iterall "1.1.3"
86+
87+
88+
version "1.1.3"
89+
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.1.3.tgz#1cbbff96204056dde6656e2ed2e2226d0e6d72c9"
90+
91+
locate-path@^2.0.0:
92+
version "2.0.0"
93+
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
94+
dependencies:
95+
p-locate "^2.0.0"
96+
path-exists "^3.0.0"
97+
98+
p-limit@^1.1.0:
99+
version "1.1.0"
100+
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.1.0.tgz#b07ff2d9a5d88bec806035895a2bab66a27988bc"
101+
102+
p-locate@^2.0.0:
103+
version "2.0.0"
104+
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43"
105+
dependencies:
106+
p-limit "^1.1.0"
107+
108+
path-exists@^3.0.0:
109+
version "3.0.0"
110+
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
111+
112+
source-map-support@^0.5.0:
113+
version "0.5.0"
114+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.0.tgz#2018a7ad2bdf8faf2691e5fddab26bed5a2bacab"
115+
dependencies:
116+
source-map "^0.6.0"
117+
118+
source-map@^0.6.0:
119+
version "0.6.1"
120+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
121+
122+
uuid@^3.1.0:
123+
version "3.1.0"
124+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

0 commit comments

Comments
 (0)