Skip to content

Commit e4c3239

Browse files
committed
chore: udpate swapi datasource, add swapi rest
1 parent 5805b0b commit e4c3239

File tree

9 files changed

+101
-30
lines changed

9 files changed

+101
-30
lines changed

handler/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2015-present, Facebook, Inc.
2+
* Copyright (c) 2020, GraphQL Contributors
33
* All rights reserved.
44
*
55
* This source code is licensed under the license found in the

handler/swapi.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
const awsServerlessExpress = require('aws-serverless-express');
11+
12+
const app = require('../lib/swapi-rest');
13+
14+
// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
15+
// due to a compressed response (e.g. gzip) which has not been handled correctly
16+
// by aws-serverless-express and/or API Gateway. Add the necessary MIME types to
17+
// binaryMimeTypes below, then redeploy (`npm run package-deploy`)
18+
const binaryMimeTypes = [
19+
'application/javascript',
20+
'application/json',
21+
'font/eot',
22+
'font/opentype',
23+
'font/otf',
24+
'image/jpeg',
25+
'image/png',
26+
'image/svg+xml',
27+
'text/css',
28+
'text/html',
29+
'text/javascript',
30+
];
31+
32+
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
33+
34+
exports.handler = (event, context) =>
35+
awsServerlessExpress.proxy(server, event, context);

scripts/download.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function cacheResources() {
3333
const cache = {};
3434

3535
for (const name of resources) {
36-
let url = `https://swapi.co/api/${name}/`;
36+
let url = `https://raw.githubusercontent.com/johnlindquist/swapi-json-server/master/${name}.json`;
3737

3838
while (url != null) {
3939
console.error(url);

scripts/mocha-bootload.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
2-
* Copyright (c) 2015-present, Facebook, Inc.
3-
* All rights reserved.
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.
47
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
9-
109
process.env.NODE_ENV = 'test';

scripts/print-schema.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* Copyright (c) 2015-present, Facebook, Inc.
3-
* All rights reserved.
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.
47
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

1010
import swapiSchema from '../src/schema';

scripts/serve-public.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* Copyright (c) 2018-present, Facebook, Inc.
3-
* All rights reserved.
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.
47
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

1010
import express from 'express';

scripts/store-schema.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/**
2-
* Copyright (c) 2015-present, Facebook, Inc.
3-
* All rights reserved.
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.
47
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

1010
import swapiSchema from '../src/schema';
1111
import { printSchema } from 'graphql/utilities';
12-
import { writeFileSync } from 'fs'
12+
import { writeFileSync } from 'fs';
1313

1414
try {
1515
var output = printSchema(swapiSchema);
16-
writeFileSync('schema.graphql', output, 'utf8')
16+
writeFileSync('schema.graphql', output, 'utf8');
1717
} catch (error) {
1818
console.error(error);
1919
console.error(error.stack);

scripts/watch.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* Copyright (c) 2015-present, Facebook, Inc.
3-
* All rights reserved.
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.
47
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

1010
import sane from 'sane';

src/swapi-rest.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
const Express = require('express');
11+
12+
const data = require('../cache/data.json');
13+
14+
const resources = [
15+
'people',
16+
'starships',
17+
'vehicles',
18+
'species',
19+
'planets',
20+
'films',
21+
];
22+
23+
const app = new Express();
24+
25+
resources.forEach(r => {
26+
app.get(`/api/${r}/`, (req, res, next) => {
27+
if (!data || !data[r]) {
28+
res.status(500);
29+
res.error(`bad data, missing file or invalid swapi resource '${r}'`);
30+
}
31+
res.status(200);
32+
res.json({ results: data[r] });
33+
next();
34+
});
35+
});
36+
37+
module.exports = app;

0 commit comments

Comments
 (0)