Skip to content

Commit e66366b

Browse files
committed
chore: attempt netlify function
1 parent 5327791 commit e66366b

File tree

6 files changed

+128
-15
lines changed

6 files changed

+128
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ lerna-debug.log
2626
.yarnrc
2727
yarn-1.18.0.js
2828
*.orig
29+
30+
# Local Netlify folder
31+
.netlify

functions/schema-demo.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* example using https://github.com/awslabs/aws-serverless-express */
2+
const express = require('express');
3+
const graphqlHTTP = require('express-graphql');
4+
const awsServerlessExpress = require('aws-serverless-express');
5+
const schema = require('../packages/graphiql/test/schema');
6+
const cors = require('cors');
7+
8+
const binaryMimeTypes = [
9+
'application/javascript',
10+
'application/json',
11+
'font/eot',
12+
'font/opentype',
13+
'font/otf',
14+
'image/jpeg',
15+
'image/png',
16+
'image/svg+xml',
17+
'text/css',
18+
'text/html',
19+
'text/javascript',
20+
];
21+
22+
const app = express();
23+
24+
app.use(cors({ origin: '*' }));
25+
26+
// Requests to /graphql redirect to /
27+
app.all('/graphql', (req, res) => res.redirect('/'));
28+
29+
// Finally, serve up the GraphQL Schema itself
30+
app.use(
31+
'/',
32+
graphqlHTTP(() => ({ schema })),
33+
);
34+
35+
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
36+
37+
exports.handler = (event, context) =>
38+
awsServerlessExpress.proxy(server, event, context);
39+
40+
// // Server
41+
// app.post('/graphql', graphqlHTTP({ schema }));
42+
43+
// // app.get('/graphql', graphQLMiddleware);
44+
// // Export Lambda handler
45+
46+
// exports.handler = serverless(app, {
47+
// httpMethod: 'POST'
48+
// })

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,23 @@
8282
"@octokit/rest": "^18.0.12",
8383
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
8484
"@testing-library/jest-dom": "^5.4.0",
85+
"@types/aws-serverless-express": "^3.3.3",
8586
"@types/codemirror": "^0.0.90",
8687
"@types/express": "^4.17.11",
8788
"@types/fetch-mock": "^7.3.2",
8889
"@types/jest": "^26.0.20",
89-
"@types/node": "^13.11.1",
90+
"@types/node": "^14.14.22",
9091
"@types/prettier": "^2.0.0",
9192
"@types/theme-ui": "^0.3.1",
9293
"@types/ws": "^7.4.0",
9394
"@typescript-eslint/eslint-plugin": "^4.14.0",
9495
"@typescript-eslint/parser": "^4.14.0",
96+
"aws-serverless-express": "^3.4.0",
9597
"babel-eslint": "^10.1.0",
9698
"babel-jest": "^25.3.0",
9799
"conventional-changelog-conventionalcommits": "^4.2.3",
98100
"copy": "^0.3.2",
101+
"cors": "^2.8.5",
99102
"cross-env": "^7.0.2",
100103
"cypress": "^4.7.0",
101104
"eslint": "^6.8.0",
@@ -108,6 +111,7 @@
108111
"eslint-plugin-prefer-object-spread": "1.2.1",
109112
"eslint-plugin-react": "7.19.0",
110113
"eslint-plugin-react-hooks": "^3.0.0",
114+
"express": "^4.17.1",
111115
"fetch-mock": "6.5.2",
112116
"flow-bin": "^0.119.1",
113117
"husky": "^4.2.3",
@@ -120,6 +124,7 @@
120124
"mkdirp": "^1.0.4",
121125
"prettier": "^2.0.4",
122126
"rimraf": "^3.0.2",
127+
"serverless-http": "^2.7.0",
123128
"ts-jest": "^25.3.1",
124129
"typedoc": "^0.19.2",
125130
"typescript": "^4.1.3",

packages/graphiql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"cross-env": "^7.0.0",
7272
"css-loader": "3.4.2",
7373
"cssnano": "^4.1.10",
74-
"express": "4.17.1",
74+
"express": "^4.17.1",
7575
"express-graphql": "experimental-stream-defer",
7676
"fork-ts-checker-webpack-plugin": "4.1.3",
7777
"graphql": "experimental-stream-defer",

packages/graphiql/resources/renderExample.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/**
2-
* This GraphiQL example illustrates how to use some of GraphiQL's props
3-
* in order to enable reading and updating the URL parameters, making
4-
* link sharing of queries a little bit easier.
2+
* UMD GraphiQL Example
53
*
6-
* This is only one example of this kind of feature, GraphiQL exposes
7-
* various React params to enable interesting integrations.
4+
* This is a simple example that provides a primitive query string parser on top of GraphiQL props
5+
* It assumes a global umd GraphiQL, which would be provided by an index.html in the default example
6+
*
7+
* It is used by:
8+
* - the netlify demo
9+
* - end to end tests
10+
* - webpack dev server
811
*/
912

1013
// Parse the search string to get url parameters.
@@ -89,9 +92,7 @@ function updateURL() {
8992
}
9093

9194
const isDev = window.location.hostname.match(/localhost$/);
92-
const api = isDev
93-
? '/graphql'
94-
: 'https://swapi-graphql.netlify.app/.netlify/functions/index';
95+
const api = isDev ? '/graphql' : '/.netlify/functions/schema-demo';
9596

9697
// Render <GraphiQL /> into the body.
9798
// See the README in the top level of this module to learn more about

yarn.lock

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5411,6 +5411,20 @@
54115411
resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-4.2.0.tgz#14264692a9d6e2fa4db3df5e56e94b5e25647ac0"
54125412
integrity sha512-iIgQNzCm0v7QMhhe4Jjn9uRh+I6GoPmt03CbEtwx3ao8/EfoQcmgtqH4vQ5Db/lxiIGaWDv6nwvunuh0RyX0+A==
54135413

5414+
"@types/aws-lambda@*", "@types/aws-lambda@^8.10.56":
5415+
version "8.10.71"
5416+
resolved "https://registry.yarnpkg.com/@types/aws-lambda/-/aws-lambda-8.10.71.tgz#ab3084038411ce42f63b975e67aafb163f3aa353"
5417+
integrity sha512-l0Lag6qq06AlKllprAJ3pbgVUbXCjRGRb7VpHow8IMn2BMHTPR0t5OD97/w8CR1+wA5XZuWQoXLjYvdlk2kQrQ==
5418+
5419+
"@types/aws-serverless-express@^3.3.3":
5420+
version "3.3.3"
5421+
resolved "https://registry.yarnpkg.com/@types/aws-serverless-express/-/aws-serverless-express-3.3.3.tgz#8af184bf16e1ba0269de318ac7b7fd638c7df70c"
5422+
integrity sha512-gIPinyiEsda2Z6Dx6GdQs47/GXaBGEGOMkYWtmqFDsVSDHzWtnIKBBBVQKyMdcK/0ZXa31zzlT+CobFnwNbsTQ==
5423+
dependencies:
5424+
"@types/aws-lambda" "*"
5425+
"@types/express" "*"
5426+
"@types/node" "*"
5427+
54145428
"@types/babel__core@^7.1.0":
54155429
version "7.1.9"
54165430
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.9.tgz#77e59d438522a6fb898fa43dc3455c6e72f3963d"
@@ -5518,7 +5532,7 @@
55185532
"@types/qs" "*"
55195533
"@types/range-parser" "*"
55205534

5521-
"@types/express@^4.17.11":
5535+
"@types/express@*", "@types/express@^4.17.11":
55225536
version "4.17.11"
55235537
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.11.tgz#debe3caa6f8e5fcda96b47bd54e2f40c4ee59545"
55245538
integrity sha512-no+R6rW60JEc59977wIxreQVsIEOAYwgCqldrA/vkpCnbD7MqTefO97lmoBe4WE0F156bC4uLSP1XHDOySnChg==
@@ -5653,7 +5667,7 @@
56535667
dependencies:
56545668
"@types/node" "*"
56555669

5656-
"@types/node@*", "@types/node@>= 8", "@types/node@^13.11.1":
5670+
"@types/node@*", "@types/node@>= 8":
56575671
version "13.11.1"
56585672
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.1.tgz#49a2a83df9d26daacead30d0ccc8762b128d53c7"
56595673
integrity sha512-eWQGP3qtxwL8FGneRrC5DwrJLGN4/dH1clNTuLfN81HCrxVtxRjygDTUoZJ5ASlDEeo0ppYFQjQIlXhtXpOn6g==
@@ -5663,6 +5677,11 @@
56635677
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.18.tgz#e932b06eb33294f5b97a67de3b820fc6f456ad1c"
56645678
integrity sha512-nru5D2PxzwzWyo3ocADAkzbc5H1KxVJMmX8oco9Fe5c+4vv6+MMp93wPq6ADqwHAwDtNH55eTCNGVaIZHZsAFQ==
56655679

5680+
"@types/node@^14.14.22":
5681+
version "14.14.22"
5682+
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.22.tgz#0d29f382472c4ccf3bd96ff0ce47daf5b7b84b18"
5683+
integrity sha512-g+f/qj/cNcqKkc3tFqlXOYjrmZA+jNBiDzbP3kH+B+otKFqAdPgVTGP1IeKRdMml/aE69as5S4FqtxAbl+LaMw==
5684+
56665685
"@types/normalize-package-data@^2.4.0":
56675686
version "2.4.0"
56685687
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
@@ -6039,6 +6058,14 @@
60396058
"@typescript-eslint/types" "4.14.0"
60406059
eslint-visitor-keys "^2.0.0"
60416060

6061+
"@vendia/serverless-express@^3.4.0":
6062+
version "3.4.0"
6063+
resolved "https://registry.yarnpkg.com/@vendia/serverless-express/-/serverless-express-3.4.0.tgz#156f47d364b067ae6fa678a914c51887f494321a"
6064+
integrity sha512-/UAAbi9qRjUtjRISt5MJ1sfhtrHb26hqQ0nvE5qhMLsAdR5H7ErBwPD8Q/v2OENKm0iWsGwErIZEg7ebUeFDjQ==
6065+
dependencies:
6066+
binary-case "^1.0.0"
6067+
type-is "^1.6.16"
6068+
60426069
"@webassemblyjs/[email protected]":
60436070
version "1.8.5"
60446071
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359"
@@ -7008,6 +7035,15 @@ autoprefixer@^9.6.1, autoprefixer@^9.7.2:
70087035
postcss "^7.0.32"
70097036
postcss-value-parser "^4.1.0"
70107037

7038+
aws-serverless-express@^3.4.0:
7039+
version "3.4.0"
7040+
resolved "https://registry.yarnpkg.com/aws-serverless-express/-/aws-serverless-express-3.4.0.tgz#74153b8cc80dbd2c6a32a51e6d353a325c2710d7"
7041+
integrity sha512-YG9ZjAOI9OpwqDDWzkRc3kKJYJuR7gTMjLa3kAWopO17myoprxskCUyCEee+RKe34tcR4UNrVtgAwW5yDe74bw==
7042+
dependencies:
7043+
"@vendia/serverless-express" "^3.4.0"
7044+
binary-case "^1.0.0"
7045+
type-is "^1.6.16"
7046+
70117047
aws-sign2@~0.7.0:
70127048
version "0.7.0"
70137049
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
@@ -7587,6 +7623,11 @@ big.js@^5.2.2:
75877623
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
75887624
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
75897625

7626+
binary-case@^1.0.0:
7627+
version "1.1.4"
7628+
resolved "https://registry.yarnpkg.com/binary-case/-/binary-case-1.1.4.tgz#d687104d59e38f2b9e658d3a58936963c59ab931"
7629+
integrity sha512-9Kq8m6NZTAgy05Ryuh7U3Qc4/ujLQU1AZ5vMw4cr3igTdi5itZC6kCNrRr2X8NzPiDn2oUIFTfa71DKMnue/Zg==
7630+
75907631
binary-extensions@^1.0.0:
75917632
version "1.13.1"
75927633
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
@@ -8975,6 +9016,14 @@ corejs-upgrade-webpack-plugin@^2.2.0:
89759016
resolve-from "^5.0.0"
89769017
webpack "^4.38.0"
89779018

9019+
cors@^2.8.5:
9020+
version "2.8.5"
9021+
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
9022+
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
9023+
dependencies:
9024+
object-assign "^4"
9025+
vary "^1"
9026+
89789027
[email protected], cosmiconfig@^6.0.0:
89799028
version "6.0.0"
89809029
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-6.0.0.tgz#da4fee853c52f6b1e6935f41c1a2fc50bd4a9982"
@@ -16302,7 +16351,7 @@ oauth-sign@~0.9.0:
1630216351
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455"
1630316352
integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==
1630416353

16305-
object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
16354+
object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
1630616355
version "4.1.1"
1630716356
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
1630816357
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
@@ -19845,6 +19894,13 @@ serve@^11.3.0:
1984519894
serve-handler "6.1.3"
1984619895
update-check "1.5.2"
1984719896

19897+
serverless-http@^2.7.0:
19898+
version "2.7.0"
19899+
resolved "https://registry.yarnpkg.com/serverless-http/-/serverless-http-2.7.0.tgz#352ca38cbbba58dc71dcfb11bb27c92c3c81fe69"
19900+
integrity sha512-iWq0z1X2Xkuvz6wL305uCux/SypbojHlYsB5bzmF5TqoLYsdvMNIoCsgtWjwqWoo3AR2cjw3zAmHN2+U6mF99Q==
19901+
optionalDependencies:
19902+
"@types/aws-lambda" "^8.10.56"
19903+
1984819904
set-blocking@^2.0.0, set-blocking@~2.0.0:
1984919905
version "2.0.0"
1985019906
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
@@ -21390,7 +21446,7 @@ type-fest@^0.8.1:
2139021446
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
2139121447
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==
2139221448

21393-
type-is@~1.6.17, type-is@~1.6.18:
21449+
type-is@^1.6.16, type-is@~1.6.17, type-is@~1.6.18:
2139421450
version "1.6.18"
2139521451
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131"
2139621452
integrity sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==
@@ -21824,7 +21880,7 @@ validate-npm-package-name@^3.0.0:
2182421880
dependencies:
2182521881
builtins "^1.0.3"
2182621882

21827-
vary@~1.1.2:
21883+
vary@^1, vary@~1.1.2:
2182821884
version "1.1.2"
2182921885
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
2183021886
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=

0 commit comments

Comments
 (0)