Skip to content

Commit 4f16799

Browse files
committed
Switch SW API example to SDL
1 parent f2070c8 commit 4f16799

File tree

3 files changed

+250
-426
lines changed

3 files changed

+250
-426
lines changed

src/__tests__/starWarsData.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,9 @@ const droidData = {
9393
* These are Flow types which correspond to the schema.
9494
* They represent the shape of the data visited during field resolution.
9595
*/
96-
export type Character = {
97-
id: string,
98-
name: string,
99-
friends: Array<string>,
100-
appearsIn: Array<number>,
101-
};
96+
export type CharacterData = HumanData | DroidData;
10297

103-
export type Human = {
98+
export type HumanData = {
10499
type: 'Human',
105100
id: string,
106101
name: string,
@@ -109,7 +104,7 @@ export type Human = {
109104
homePlanet: string,
110105
};
111106

112-
export type Droid = {
107+
export type DroidData = {
113108
type: 'Droid',
114109
id: string,
115110
name: string,
@@ -121,23 +116,15 @@ export type Droid = {
121116
/**
122117
* Helper function to get a character by ID.
123118
*/
124-
function getCharacter(id) {
119+
export function getCharacter(id: string): Promise<CharacterData> {
125120
// Returning a promise just to illustrate GraphQL.js's support.
126121
return Promise.resolve(humanData[id] || droidData[id]);
127122
}
128123

129-
/**
130-
* Allows us to query for a character's friends.
131-
*/
132-
export function getFriends(character: Character): Array<Promise<Character>> {
133-
// Notice that GraphQL accepts Arrays of Promises.
134-
return character.friends.map(id => getCharacter(id));
135-
}
136-
137124
/**
138125
* Allows us to fetch the undisputed hero of the Star Wars trilogy, R2-D2.
139126
*/
140-
export function getHero(episode: number): Character {
127+
export function getHero(episode: number): CharacterData {
141128
if (episode === 5) {
142129
// Luke is the hero of Episode V.
143130
return luke;
@@ -149,13 +136,13 @@ export function getHero(episode: number): Character {
149136
/**
150137
* Allows us to query for the human with the given id.
151138
*/
152-
export function getHuman(id: string): Human {
139+
export function getHuman(id: string): HumanData {
153140
return humanData[id];
154141
}
155142

156143
/**
157144
* Allows us to query for the droid with the given id.
158145
*/
159-
export function getDroid(id: string): Droid {
146+
export function getDroid(id: string): DroidData {
160147
return droidData[id];
161148
}

0 commit comments

Comments
 (0)