Skip to content

Commit 0e32ca2

Browse files
committed
strip out swapi
1 parent 66eb26a commit 0e32ca2

24 files changed

+4729
-9749
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
examples/swapi/swapi-loaders.js linguist-generated=true
1+
examples/spaceapi-flow/spaceapi-loaders.js linguist-generated=true
File renamed without changes.
File renamed without changes.

examples/spaceapi-flow/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
flow-typed

examples/swapi/Makefile renamed to examples/spaceapi-flow/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
node_modules: package.json
22
yarn
33

4-
.PHONY: swapi-loaders.js
5-
swapi-loaders.js:
6-
node ../../lib/index.js --config swapi.dataloader-config.yaml --output swapi-loaders.js
4+
spaceapi-loaders.js:
5+
node ../../lib/index.js --config spaceapi.dataloader-config.yaml --output spaceapi-loaders.js
76

87
flow-typed: node_modules
98
yarn flow-typed install
File renamed without changes.

examples/spaceapi-flow/clientlib.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Fake clientlib for a fake "Space People" REST API server.
3+
* https://example.com/space-api
4+
* @flow
5+
*/
6+
7+
const { inspect } = require('util');
8+
9+
export type Planet = $ReadOnly<{|
10+
id: number,
11+
name: string,
12+
diameter: number,
13+
gravity: string,
14+
climate: string,
15+
population: number,
16+
residents: $ReadOnlyArray <number>,
17+
|}>;
18+
19+
export type Person = $ReadOnly<{|
20+
id: number,
21+
name: string,
22+
height: number,
23+
hair_color: string,
24+
home_planet: number,
25+
|}>;
26+
27+
export type SpacePeopleClientlibTypes = {|
28+
getPlanets: ({| planet_ids: $ReadOnlyArray<number> |}) => Promise<$ReadOnlyArray<Planet>>,
29+
getPeople: ({| people_ids: $ReadOnlyArray<number> |}) => Promise<$ReadOnlyArray<Person>>,
30+
|};
31+
32+
const FAKE_PLANETS: $ReadOnlyArray<Planet> = [
33+
{
34+
id: 1,
35+
name: "Proxima Centauri",
36+
diameter: 12000,
37+
gravity: "1 standard",
38+
climate: "hot",
39+
population: 500000,
40+
residents: [1, 2, 3],
41+
},
42+
{
43+
id: 2,
44+
name: "Kepler-186f",
45+
diameter: 8000,
46+
gravity: "0.8 standard",
47+
climate: "icy",
48+
population: 200000,
49+
residents: [4, 5],
50+
},
51+
];
52+
53+
const FAKE_PEOPLE: $ReadOnlyArray<Person> = [
54+
{
55+
id: 1,
56+
name: "Alice",
57+
height: 180,
58+
hair_color: "blue",
59+
home_planet: 1,
60+
},
61+
{
62+
id: 2,
63+
name: "Bob",
64+
height: 175,
65+
hair_color: "green",
66+
home_planet: 1,
67+
},
68+
{
69+
id: 3,
70+
name: "Charlie",
71+
height: 165,
72+
hair_color: "red",
73+
home_planet: 1,
74+
},
75+
{
76+
id: 4,
77+
name: "Dave",
78+
height: 190,
79+
hair_color: "none",
80+
home_planet: 2,
81+
},
82+
{
83+
id: 5,
84+
name: "Eve",
85+
height: 170,
86+
hair_color: "blue",
87+
home_planet: 2,
88+
},
89+
];
90+
91+
function CreateSpacePeopleClientlib(): SpacePeopleClientlibTypes {
92+
return {
93+
getPlanets: ({ planet_ids }) => Promise.resolve(planet_ids.map((id) => {
94+
const planet = FAKE_PLANETS.find((p) => p.id === id);
95+
if (!planet) {
96+
throw new Error(`Planet with id ${inspect(id)} not found`);
97+
}
98+
return planet;
99+
})),
100+
getPeople: ({ people_ids }) => Promise.resolve(people_ids.map((id) => {
101+
const person = FAKE_PEOPLE.find((p) => p.id === id);
102+
if (!person) {
103+
throw new Error(`Person with id ${inspect(id)} not found`);
104+
}
105+
return person;
106+
})),
107+
}
108+
};
109+
110+
module.exports = CreateSpacePeopleClientlib;

examples/swapi/package.json renamed to examples/spaceapi-flow/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
},
99
"dependencies": {
1010
"dataloader": "^2.0.0",
11-
"graphql": "15.0.0",
12-
"node-fetch": "^2.6.0"
11+
"dataloader-codegen": "file:../../",
12+
"graphql": "16.x"
1313
},
1414
"engines": {
15-
"node": ">=10"
15+
"node": ">=20"
1616
}
1717
}

0 commit comments

Comments
 (0)