Skip to content

Clarify connections with naming, count field, and convenience field #3

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

Merged
merged 1 commit into from
Aug 28, 2015
Merged
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
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
[libs]

[options]
suppress_comment=.*\\$FlowIssue
16 changes: 13 additions & 3 deletions swapi/src/schema/__tests__/apiHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ describe('API Helper', () => {
});

it('Gets all pages at once', async () => {
var people = await getObjectsByType('people');
expect(people.length).to.equal(82);
expect(people[0].name).to.equal('Luke Skywalker');
var {objects, totalCount} = await getObjectsByType('people');
expect(objects.length).to.equal(82);
expect(totalCount).to.equal(82);
expect(objects[0].name).to.equal('Luke Skywalker');
});

it('Gets first page and correct count', async () => {
var {objects, totalCount} = await getObjectsByType('people', {first: 5});
// Should only fetch the first page which has 10 items
expect(objects.length).to.equal(10);
// Count should still be accurate, though
expect(totalCount).to.equal(82);
expect(objects[0].name).to.equal('Luke Skywalker');
});

it('Gets a person by ID', async () => {
Expand Down
43 changes: 23 additions & 20 deletions swapi/src/schema/__tests__/film.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe('Film type', async () => {
director
producers
releaseDate
species(first:1) { edges { node { name } } }
starships(first:1) { edges { node { name } } }
vehicles(first:1) { edges { node { name } } }
characters(first:1) { edges { node { name } } }
planets(first:1) { edges { node { name } } }
speciesConnection(first:1) { edges { node { name } } }
starshipConnection(first:1) { edges { node { name } } }
vehicleConnection(first:1) { edges { node { name } } }
characterConnection(first:1) { edges { node { name } } }
planetConnection(first:1) { edges { node { name } } }
}
}`;
var result = await swapi(query);
Expand All @@ -78,11 +78,11 @@ describe('Film type', async () => {
director: 'George Lucas',
producers: [ 'Gary Kurtz', 'Rick McCallum' ],
releaseDate: '1977-05-25',
species: { edges: [ { node: { name: 'Human' } } ] },
starships: { edges: [ { node: { name: 'CR90 corvette' } } ] },
vehicles: { edges: [ { node: { name: 'Sand Crawler' } } ] },
characters: { edges: [ { node: { name: 'Luke Skywalker' } } ] },
planets: { edges: [ { node: { name: 'Tatooine' } } ] }
speciesConnection: { edges: [ { node: { name: 'Human' } } ] },
starshipConnection: { edges: [ { node: { name: 'CR90 corvette' } } ] },
vehicleConnection: { edges: [ { node: { name: 'Sand Crawler' } } ] },
characterConnection: { edges: [ { node: { name: 'Luke Skywalker' } } ] },
planetConnection: { edges: [ { node: { name: 'Tatooine' } } ] }
};
expect(result.data.film).to.deep.equal(expected);
});
Expand All @@ -94,22 +94,25 @@ describe('Film type', async () => {
});

it('Pagination query', async() => {
var query = `{ allFilms(first: 2) { edges { cursor, node { title } } } }`;
var query = `{
allFilms(first: 2) { edges { cursor, node { title } } }
}`;
var result = await swapi(query);
expect(result.data.allFilms.edges.map(e => e.node.title)).to.deep.equal([
'A New Hope',
'The Empire Strikes Back'
]);
expect(result.data.allFilms.edges.map(e => e.node.title))
.to.deep.equal([
'A New Hope',
'The Empire Strikes Back'
]);
var nextCursor = result.data.allFilms.edges[1].cursor;

var nextQuery = `{ allFilms(first: 2, after:"${nextCursor}") {
edges { cursor, node { title } } }
}`;
var nextResult = await swapi(nextQuery);
expect(nextResult.data.allFilms.edges.map(e => e.node.title)).to.deep.equal(
[
'Return of the Jedi',
'The Phantom Menace',
]);
expect(nextResult.data.allFilms.edges.map(e => e.node.title))
.to.deep.equal([
'Return of the Jedi',
'The Phantom Menace',
]);
});
});
35 changes: 19 additions & 16 deletions swapi/src/schema/__tests__/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ describe('Person type', async () => {
mass
skinColor
homeworld { name }
films(first:1) { edges { node { title } } }
filmConnection(first:1) { edges { node { title } } }
species { name }
starships(first:1) { edges { node { name } } }
vehicles(first:1) { edges { node { name } } }
starshipConnection(first:1) { edges { node { name } } }
vehicleConnection(first:1) { edges { node { name } } }
}
}`;
var result = await swapi(query);
Expand All @@ -83,10 +83,10 @@ describe('Person type', async () => {
mass: 77,
skinColor: 'fair',
homeworld: { name: 'Tatooine' },
films: { edges: [{ node: { title: 'A New Hope' } }] },
filmConnection: { edges: [{ node: { title: 'A New Hope' } }] },
species: null,
starships: { edges: [{ node: { name: 'X-wing' } }] },
vehicles: { edges: [{ node: { name: 'Snowspeeder' } }] },
starshipConnection: { edges: [{ node: { name: 'X-wing' } }] },
vehicleConnection: { edges: [{ node: { name: 'Snowspeeder' } }] },
};
expect(result.data.person).to.deep.equal(expected);
});
Expand All @@ -98,23 +98,26 @@ describe('Person type', async () => {
});

it('Pagination query', async() => {
var query = `{ allPeople(first: 2) { edges { cursor, node { name } } } }`;
var query = `{
allPeople(first: 2) { edges { cursor, node { name } } }
}`;
var result = await swapi(query);
expect(result.data.allPeople.edges.map(e => e.node.name)).to.deep.equal([
'Luke Skywalker',
'C-3PO',
]);
expect(result.data.allPeople.edges.map(e => e.node.name))
.to.deep.equal([
'Luke Skywalker',
'C-3PO',
]);
var nextCursor = result.data.allPeople.edges[1].cursor;

var nextQuery = `{ allPeople(first: 2, after:"${nextCursor}") {
edges { cursor, node { name } } }
}`;
var nextResult = await swapi(nextQuery);
expect(nextResult.data.allPeople.edges.map(e => e.node.name)).to.deep.equal(
[
'R2-D2',
'Darth Vader',
]);
expect(nextResult.data.allPeople.edges.map(e => e.node.name))
.to.deep.equal([
'R2-D2',
'Darth Vader',
]);
});

describe('Edge cases', () => {
Expand Down
31 changes: 17 additions & 14 deletions swapi/src/schema/__tests__/planet.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ describe('Planet type', async () => {
climates
terrains
surfaceWater
residents(first:1) { edges { node { name } } }
films(first:1) { edges { node { title } } }
residentConnection(first:1) { edges { node { name } } }
filmConnection(first:1) { edges { node { title } } }
}
}`;
var result = await swapi(query);
var expected = {
climates: [ 'arid' ],
diameter: 10465,
films: { edges: [ { node: { title: 'A New Hope' } } ] },
filmConnection: { edges: [ { node: { title: 'A New Hope' } } ] },
gravity: '1 standard',
name: 'Tatooine',
orbitalPeriod: 304,
population: 200000,
residents: { edges: [ { node: { name: 'Luke Skywalker' } } ] },
residentConnection: { edges: [ { node: { name: 'Luke Skywalker' } } ] },
rotationPeriod: 23,
surfaceWater: 1,
terrains: [ 'dessert' ] // [sic]
Expand All @@ -94,22 +94,25 @@ describe('Planet type', async () => {
});

it('Pagination query', async() => {
var query = `{ allPlanets(first: 2) { edges { cursor, node { name } } } }`;
var query = `{
allPlanets(first: 2) { edges { cursor, node { name } } }
}`;
var result = await swapi(query);
expect(result.data.allPlanets.edges.map(e => e.node.name)).to.deep.equal([
'Tatooine',
'Alderaan',
]);
expect(result.data.allPlanets.edges.map(e => e.node.name))
.to.deep.equal([
'Tatooine',
'Alderaan',
]);
var nextCursor = result.data.allPlanets.edges[1].cursor;

var nextQuery = `{ allPlanets(first: 2, after:"${nextCursor}") {
edges { cursor, node { name } } }
}`;
var nextResult = await swapi(nextQuery);
expect(nextResult.data.allPlanets.edges.map(e => e.node.name)).to.deep.equal(
[
'Yavin IV',
'Hoth',
]);
expect(nextResult.data.allPlanets.edges.map(e => e.node.name))
.to.deep.equal([
'Yavin IV',
'Hoth',
]);
});
});
29 changes: 16 additions & 13 deletions swapi/src/schema/__tests__/species.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ describe('Species type', async () => {
skinColors
language
homeworld { name }
people(first:1) { edges { node { name } } }
films(first:1) { edges { node { title } } }
personConnection(first:1) { edges { node { name } } }
filmConnection(first:1) { edges { node { title } } }
}
}`;
var result = await swapi(query);
Expand All @@ -82,8 +82,8 @@ describe('Species type', async () => {
homeworld: { name: 'Rodia' },
language: 'Galatic Basic', // [sic]
name: 'Rodian',
people: { edges: [ { node: { name: 'Greedo' } } ] },
films: { edges: [ { node: { title: 'A New Hope' } } ] },
personConnection: { edges: [ { node: { name: 'Greedo' } } ] },
filmConnection: { edges: [ { node: { title: 'A New Hope' } } ] },
skinColors: ['green', 'blue']
};
expect(result.data.species).to.deep.equal(expected);
Expand All @@ -96,23 +96,26 @@ describe('Species type', async () => {
});

it('Pagination query', async() => {
var query = `{ allSpecies(first: 2) { edges { cursor, node { name } } } }`;
var query = `{
allSpecies(first: 2) { edges { cursor, node { name } } }
}`;
var result = await swapi(query);
expect(result.data.allSpecies.edges.map(e => e.node.name)).to.deep.equal([
'Human',
'Droid',
]);
expect(result.data.allSpecies.edges.map(e => e.node.name))
.to.deep.equal([
'Human',
'Droid',
]);
var nextCursor = result.data.allSpecies.edges[1].cursor;

var nextQuery = `{ allSpecies(first: 2, after:"${nextCursor}") {
edges { cursor, node { name } } }
}`;
var nextResult = await swapi(nextQuery);
expect(nextResult.data.allSpecies.edges.map(e => e.node.name))
.to.deep.equal([
'Wookie', // [sic]
'Rodian'
]);
.to.deep.equal([
'Wookie', // [sic]
'Rodian'
]);
});

describe('Edge cases', () => {
Expand Down
34 changes: 19 additions & 15 deletions swapi/src/schema/__tests__/starship.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ describe('Starship type', async () => {
MGLT
cargoCapacity
consumables
films(first:1) { edges { node { title } } }
pilots(first:1) { edges { node { name } } }
filmConnection(first:1) { edges { node { title } } }
pilotConnection(first:1) { edges { node { name } } }
}
}`;
var result = await swapi(query);
Expand All @@ -81,15 +81,15 @@ describe('Starship type', async () => {
consumables: '3 years',
costInCredits: 1000000000000,
crew: '342,953',
films: { edges: [ { node: { title: 'A New Hope' } } ] },
filmConnection: { edges: [ { node: { title: 'A New Hope' } } ] },
hyperdriveRating: 4,
length: 120000,
manufacturers: [ 'Imperial Department of Military Research', 'Sienar Fleet Systems' ],
maxAtmospheringSpeed: null,
model: 'DS-1 Orbital Battle Station',
name: 'Death Star',
passengers: '843,342',
pilots: { edges: [] },
pilotConnection: { edges: [] },
starshipClass: 'Deep Space Mobile Battlestation'
};
expect(result.data.starship).to.deep.equal(expected);
Expand All @@ -102,30 +102,34 @@ describe('Starship type', async () => {
});

it('Pagination query', async() => {
var query = `{ allStarships(first: 2) { edges { cursor, node { name } } } }`;
var query = `{
allStarships(first: 2) { edges { cursor, node { name } } }
}`;
var result = await swapi(query);
expect(result.data.allStarships.edges.map(e => e.node.name)).to.deep.equal([
'CR90 corvette',
'Star Destroyer',
]);
expect(result.data.allStarships.edges.map(e => e.node.name))
.to.deep.equal([
'CR90 corvette',
'Star Destroyer',
]);
var nextCursor = result.data.allStarships.edges[1].cursor;

var nextQuery = `{ allStarships(first: 2, after:"${nextCursor}") {
edges { cursor, node { name } } }
}`;
var nextResult = await swapi(nextQuery);
expect(nextResult.data.allStarships.edges.map(e => e.node.name)).to.deep.equal(
[
'Sentinel-class landing craft',
'Death Star',
]);
expect(nextResult.data.allStarships.edges.map(e => e.node.name))
.to.deep.equal([
'Sentinel-class landing craft',
'Death Star',
]);
});

describe('Edge cases', () => {
it('Returns real speed when set to not n/a', async () => {
var query = `{ starship(starshipID: 5) { name, maxAtmospheringSpeed } }`;
var result = await swapi(query);
expect(result.data.starship.name).to.equal('Sentinel-class landing craft');
expect(result.data.starship.name)
.to.equal('Sentinel-class landing craft');
expect(result.data.starship.maxAtmospheringSpeed).to.equal(1000);
});
});
Expand Down
Loading