Skip to content

Commit 1edea3c

Browse files
committed
code review + minimize html 🗜
1 parent 8236049 commit 1edea3c

File tree

4 files changed

+92
-31
lines changed

4 files changed

+92
-31
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"@types/express": "^4.0.37",
3232
"@types/graphql": "^0.11.5",
3333
"@types/node-fetch": "^1.6.7",
34-
"nodemon": "^1.12.1"
34+
"nodemon": "^1.12.1",
35+
"ts-node": "^3.3.0",
36+
"typescript": "^2.5.3"
3537
}
3638
}

src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ const originUrl = process.argv[2];
1010
if (!originUrl) throw Error('Specify URL as the 1st argument!');
1111

1212
(async () => {
13-
const introspection = await graphqlFetch({query: introspectionQuery});
14-
if (introspection.errors) throw Error(JSON.stringify(introspection.errors, null, 2));
15-
const schema = buildClientSchema(introspection.data), app = express();
13+
const {errors, data} = await graphqlFetch({query: introspectionQuery});
14+
if (errors) throw Error(JSON.stringify(errors, null, 2));
15+
const schema = buildClientSchema(data);
16+
const app = express();
1617
const formatErrorFn = (err) => err;
1718
app.use('/graphql', graphqlHTTP({ schema, execute, graphiql: true, formatErrorFn }));
1819
app.get('/coverage-map', (_, res) => res.status(200).json(coverage));
1920
app.use('/coverage', express.static(path.join(__dirname, 'static')));
20-
const port = 9003;
21-
app.listen(port);
21+
app.listen(9003);
2222
console.log(`\n${green('✔')} Your GraphQL Fake API is ready to use 🚀 \n
23-
${blue('❯')} Coverage Graph:\t http://localhost:${port}/coverage
24-
${blue('❯')} GraphQL API:\t http://localhost:${port}/graphql`);
23+
${blue('❯')} Coverage Graph:\t http://localhost:9003/coverage
24+
${blue('❯')} GraphQL API:\t http://localhost:9003/graphql`);
2525
})()
2626
.catch(error => console.error(red(error.stack)));
2727

2828
async function graphqlFetch(body) {
2929
const res = await fetch(originUrl, {
3030
method: 'POST',
3131
body: JSON.stringify(body),
32-
headers: { "content-type": 'application/json' },
32+
headers: { 'content-type': 'application/json' },
3333
});
3434
if (!res.ok)
3535
throw Error(`${res.status} ${res.statusText}\n${await res.text()}`);

src/static/index.html

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset=utf-8 />
54
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
6-
<title>GraphQL Voyager</title>
75
<style>
8-
body {
9-
padding: 0;
10-
margin: 0;
11-
width: 100%;
12-
height: 100vh;
13-
overflow: hidden;
14-
}
15-
#voyager {
16-
height: 100vh;
17-
}
18-
.edge.green > path:not(.hover-path): {
19-
stroke: green;
6+
body { margin: 0; }
7+
#voyager { height: 100vh; }
8+
.edge.green > path:not(.hover-path), .edge.green > polygon {
9+
stroke: #00ff00 !important;
2010
}
2111
.field.green > polygon {
22-
fill: rgba(0,255,0,.18)
12+
fill: rgba(0,255,0,.55);
2313
}
2414
</style>
2515
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/graphql-voyager/dist/voyager.css" />
26-
<script src="//cdn.jsdelivr.net/fetch/2.0.1/fetch.min.js"/></script>
2716
<script src="//cdn.jsdelivr.net/react/15.4.2/react.min.js"></script>
2817
<script src="//cdn.jsdelivr.net/react/15.4.2/react-dom.min.js"></script>
2918
<script src="//cdn.jsdelivr.net/npm/graphql-voyager/dist/voyager.min.js"></script>
3019
</head>
3120
<body>
32-
<main id="voyager">
33-
<h1 style="text-align: center; color: #5d7e86;"> Loading... </h1>
34-
</main>
21+
<main id="voyager">Loading...</main>
3522
<script>
3623
window.addEventListener('load', function() {
3724
GraphQLVoyager.init(document.getElementById('voyager'), {
@@ -40,7 +27,7 @@ <h1 style="text-align: center; color: #5d7e86;"> Loading... </h1>
4027
.then(function (res) { return res.ok ? res.json() : res.text(); });
4128
}
4229
});
43-
setInterval(function(){
30+
setInterval(function() {
4431
fetch('/coverage-map').then(function (res) { return res.json() })
4532
.then(function (coverage) {
4633
var greenElements = document.getElementsByClassName('green');

yarn.lock

+74-2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ array-unique@^0.2.1:
122122
version "0.2.1"
123123
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53"
124124

125+
arrify@^1.0.0:
126+
version "1.0.1"
127+
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
128+
125129
asn1@~0.2.3:
126130
version "0.2.3"
127131
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86"
@@ -244,7 +248,7 @@ chalk@^1.0.0:
244248
strip-ansi "^3.0.0"
245249
supports-color "^2.0.0"
246250

247-
chalk@^2.0.1, chalk@^2.1.0:
251+
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0:
248252
version "2.1.0"
249253
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e"
250254
dependencies:
@@ -390,6 +394,10 @@ destroy@~1.0.4:
390394
version "1.0.4"
391395
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
392396

397+
diff@^3.1.0:
398+
version "3.4.0"
399+
resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c"
400+
393401
dot-prop@^4.1.0:
394402
version "4.2.0"
395403
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57"
@@ -733,6 +741,12 @@ [email protected]:
733741
version "2.16.3"
734742
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
735743

744+
homedir-polyfill@^1.0.1:
745+
version "1.0.1"
746+
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc"
747+
dependencies:
748+
parse-passwd "^1.0.0"
749+
736750
[email protected], http-errors@^1.3.0, http-errors@~1.6.2:
737751
version "1.6.2"
738752
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.2.tgz#0a002cc85707192a7e7946ceedc11155f60ec736"
@@ -1027,6 +1041,10 @@ make-dir@^1.0.0:
10271041
dependencies:
10281042
pify "^2.3.0"
10291043

1044+
make-error@^1.1.1:
1045+
version "1.3.0"
1046+
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.0.tgz#52ad3a339ccf10ce62b4040b708fe707244b8b96"
1047+
10301048
map-stream@~0.1.0:
10311049
version "0.1.0"
10321050
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194"
@@ -1246,6 +1264,10 @@ parse-glob@^3.0.4:
12461264
is-extglob "^1.0.0"
12471265
is-glob "^2.0.0"
12481266

1267+
parse-passwd@^1.0.0:
1268+
version "1.0.0"
1269+
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
1270+
12491271
parseurl@~1.3.2:
12501272
version "1.3.2"
12511273
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
@@ -1508,6 +1530,16 @@ [email protected]:
15081530
dependencies:
15091531
hoek "2.x.x"
15101532

1533+
source-map-support@^0.4.0:
1534+
version "0.4.18"
1535+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f"
1536+
dependencies:
1537+
source-map "^0.5.6"
1538+
1539+
source-map@^0.5.6:
1540+
version "0.5.7"
1541+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
1542+
15111543
15121544
version "0.3.3"
15131545
resolved "https://registry.yarnpkg.com/split/-/split-0.3.3.tgz#cd0eea5e63a211dfff7eb0f091c4133e2d0dd28f"
@@ -1575,11 +1607,15 @@ strip-ansi@^4.0.0:
15751607
dependencies:
15761608
ansi-regex "^3.0.0"
15771609

1610+
strip-bom@^3.0.0:
1611+
version "3.0.0"
1612+
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
1613+
15781614
strip-eof@^1.0.0:
15791615
version "1.0.0"
15801616
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
15811617

1582-
strip-json-comments@~2.0.1:
1618+
strip-json-comments@^2.0.0, strip-json-comments@~2.0.1:
15831619
version "2.0.1"
15841620
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
15851621

@@ -1640,6 +1676,28 @@ tough-cookie@~2.3.0:
16401676
dependencies:
16411677
punycode "^1.4.1"
16421678

1679+
ts-node@^3.3.0:
1680+
version "3.3.0"
1681+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-3.3.0.tgz#c13c6a3024e30be1180dd53038fc209289d4bf69"
1682+
dependencies:
1683+
arrify "^1.0.0"
1684+
chalk "^2.0.0"
1685+
diff "^3.1.0"
1686+
make-error "^1.1.1"
1687+
minimist "^1.2.0"
1688+
mkdirp "^0.5.1"
1689+
source-map-support "^0.4.0"
1690+
tsconfig "^6.0.0"
1691+
v8flags "^3.0.0"
1692+
yn "^2.0.0"
1693+
1694+
tsconfig@^6.0.0:
1695+
version "6.0.0"
1696+
resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-6.0.0.tgz#6b0e8376003d7af1864f8df8f89dd0059ffcd032"
1697+
dependencies:
1698+
strip-bom "^3.0.0"
1699+
strip-json-comments "^2.0.0"
1700+
16431701
tunnel-agent@^0.6.0:
16441702
version "0.6.0"
16451703
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
@@ -1657,6 +1715,10 @@ type-is@~1.6.15:
16571715
media-typer "0.3.0"
16581716
mime-types "~2.1.15"
16591717

1718+
typescript@^2.5.3:
1719+
version "2.5.3"
1720+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d"
1721+
16601722
uid-number@^0.0.6:
16611723
version "0.0.6"
16621724
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
@@ -1710,6 +1772,12 @@ uuid@^3.0.0:
17101772
version "3.1.0"
17111773
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
17121774

1775+
v8flags@^3.0.0:
1776+
version "3.0.1"
1777+
resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-3.0.1.tgz#dce8fc379c17d9f2c9e9ed78d89ce00052b1b76b"
1778+
dependencies:
1779+
homedir-polyfill "^1.0.1"
1780+
17131781
vary@~1.1.2:
17141782
version "1.1.2"
17151783
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
@@ -1759,3 +1827,7 @@ xdg-basedir@^3.0.0:
17591827
yallist@^2.1.2:
17601828
version "2.1.2"
17611829
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
1830+
1831+
yn@^2.0.0:
1832+
version "2.0.0"
1833+
resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a"

0 commit comments

Comments
 (0)