Skip to content

Commit 8b31adf

Browse files
authored
graphql-http, rewrites, redirects, explorer plugin (#222)
* graphql-http and rewrites and redirects - replace express with graphql-http, lambda function - add netlify-cli tooling to simplify npm run watch - add reverse proxy so that /graphql serves a graphql schema - add 301 redirects so that /index and /swapi redirect to /graphql - lint:fix * upgrade netlify-cli * upgrade to node 20
1 parent 6bb1fb8 commit 8b31adf

20 files changed

+23738
-9185
lines changed

.flowconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[ignore]
22
.*/coverage/.*
33
.*/scripts/.*
4-
.*/node_modules/flow-bin/.*
5-
.*/node_modules/fbjs/.*
4+
.*/node_modules/.*
65

76
[include]
87

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ node_modules
55
npm-debug.log
66
/coverage
77
/cache/data.json
8+
9+
# Local Netlify folder
10+
.netlify

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.5.0

handler/graphql.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) 2020, GraphQL Contributors
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE-examples file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
import { createHandler } from 'graphql-http/lib/use/@netlify/functions';
11+
import schema from '../lib/schema';
12+
13+
// Create the GraphQL over HTTP native fetch handler
14+
export const handler = createHandler({ schema: schema.default });

handler/index.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

handler/index.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* 301 permanently redirect /index requests to /graphql
3+
*/
4+
export const handler = async function(event) {
5+
let location = '/graphql';
6+
if (event.queryStringParameters) {
7+
location += '?' + new URLSearchParams(event.queryStringParameters);
8+
}
9+
return {
10+
statusCode: 301,
11+
headers: {
12+
Location: location,
13+
},
14+
};
15+
};

handler/swapi.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

handler/swapi.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* 301 permanently redirect /swapi requests to /graphql
3+
*/
4+
export const handler = async function(event) {
5+
let location = '/graphql';
6+
if (event.queryStringParameters) {
7+
location += '?' + new URLSearchParams(event.queryStringParameters);
8+
}
9+
return {
10+
statusCode: 301,
11+
headers: {
12+
Location: location,
13+
},
14+
};
15+
};

netlify.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
[build]
2-
functions = "netlify-lambda-lib"
2+
functions = "handler"
33
command = "npm run download && npm run build"
4+
publish = "public/"
5+
[[headers]]
6+
for = "/graphql*"
7+
[headers.values]
8+
Access-Control-Allow-Origin = "*"

0 commit comments

Comments
 (0)