Skip to content

strip out swapi + namepsace to flow #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
examples/swapi/swapi-loaders.js linguist-generated=true
examples/spaceapi-flow/spaceapi-loaders.js linguist-generated=true
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions examples/spaceapi-flow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
flow-typed
5 changes: 2 additions & 3 deletions examples/swapi/Makefile → examples/spaceapi-flow/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
node_modules: package.json
yarn

.PHONY: swapi-loaders.js
swapi-loaders.js:
node ../../lib/index.js --config swapi.dataloader-config.yaml --output swapi-loaders.js
spaceapi-loaders.js:
node ../../lib/index.js --config spaceapi.dataloader-config.yaml --output spaceapi-loaders.js

flow-typed: node_modules
yarn flow-typed install
Expand Down
File renamed without changes.
116 changes: 116 additions & 0 deletions examples/spaceapi-flow/clientlib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Fake clientlib for a fake "Space People" REST API server.
* https://example.com/space-api
* @flow
*/

const { inspect } = require('util');

export type Planet = $ReadOnly<{|
id: number,
name: string,
diameter: number,
gravity: string,
climate: string,
population: number,
residents: $ReadOnlyArray<number>,
|}>;

export type Person = $ReadOnly<{|
id: number,
name: string,
height: number,
hair_color: string,
home_planet: number,
|}>;

export type SpacePeopleClientlibTypes = {|
getPlanets: ({| planet_ids: $ReadOnlyArray<number> |}) => Promise<$ReadOnlyArray<Planet>>,
getPeople: ({| people_ids: $ReadOnlyArray<number> |}) => Promise<$ReadOnlyArray<Person>>,
|};

const FAKE_PLANETS: $ReadOnlyArray<Planet> = [
{
id: 1,
name: 'Proxima Centauri',
diameter: 12000,
gravity: '1 standard',
climate: 'hot',
population: 500000,
residents: [1, 2, 3],
},
{
id: 2,
name: 'Kepler-186f',
diameter: 8000,
gravity: '0.8 standard',
climate: 'icy',
population: 200000,
residents: [4, 5],
},
];

const FAKE_PEOPLE: $ReadOnlyArray<Person> = [
{
id: 1,
name: 'Alice',
height: 180,
hair_color: 'blue',
home_planet: 1,
},
{
id: 2,
name: 'Bob',
height: 175,
hair_color: 'green',
home_planet: 1,
},
{
id: 3,
name: 'Charlie',
height: 165,
hair_color: 'red',
home_planet: 1,
},
{
id: 4,
name: 'Dave',
height: 190,
hair_color: 'none',
home_planet: 2,
},
{
id: 5,
name: 'Eve',
height: 170,
hair_color: 'blue',
home_planet: 2,
},
];

function CreateSpacePeopleClientlib(): SpacePeopleClientlibTypes {
return {
getPlanets: ({ planet_ids }) =>
Promise.resolve(
planet_ids.map((id) => {
const planet = FAKE_PLANETS.find((p) => p.id === id);
if (!planet) {
throw new Error(`Planet with id ${inspect(id)} not found`);
}
return planet;
}),
),
getPeople: ({ people_ids }) =>
Promise.resolve(
people_ids.map((id) => {
const person = FAKE_PEOPLE.find((p) => p.id === id);
if (!person) {
throw new Error(`Person with id ${inspect(id)} not found`);
}
return person;
}),
),
};
}

module.exports = CreateSpacePeopleClientlib;
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
},
"dependencies": {
"dataloader": "^2.0.0",
"graphql": "15.0.0",
"node-fetch": "^2.6.0"
"dataloader-codegen": "file:../../",
"graphql": "16.x"
},
"engines": {
"node": ">=10"
"node": ">=20"
}
}
Loading