@@ -93,14 +93,9 @@ const droidData = {
93
93
* These are Flow types which correspond to the schema.
94
94
* They represent the shape of the data visited during field resolution.
95
95
*/
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 ;
102
97
103
- export type Human = {
98
+ export type HumanData = {
104
99
type : 'Human' ,
105
100
id : string ,
106
101
name : string ,
@@ -109,7 +104,7 @@ export type Human = {
109
104
homePlanet : string ,
110
105
} ;
111
106
112
- export type Droid = {
107
+ export type DroidData = {
113
108
type : 'Droid' ,
114
109
id : string ,
115
110
name : string ,
@@ -121,23 +116,15 @@ export type Droid = {
121
116
/**
122
117
* Helper function to get a character by ID.
123
118
*/
124
- function getCharacter ( id ) {
119
+ export function getCharacter ( id : string ) : Promise < CharacterData > {
125
120
// Returning a promise just to illustrate GraphQL.js's support.
126
121
return Promise . resolve ( humanData [ id ] || droidData [ id ] ) ;
127
122
}
128
123
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
-
137
124
/**
138
125
* Allows us to fetch the undisputed hero of the Star Wars trilogy, R2-D2.
139
126
*/
140
- export function getHero ( episode : number ) : Character {
127
+ export function getHero ( episode : number ) : CharacterData {
141
128
if ( episode === 5 ) {
142
129
// Luke is the hero of Episode V.
143
130
return luke ;
@@ -149,13 +136,13 @@ export function getHero(episode: number): Character {
149
136
/**
150
137
* Allows us to query for the human with the given id.
151
138
*/
152
- export function getHuman ( id : string ) : Human {
139
+ export function getHuman ( id : string ) : HumanData {
153
140
return humanData [ id ] ;
154
141
}
155
142
156
143
/**
157
144
* Allows us to query for the droid with the given id.
158
145
*/
159
- export function getDroid ( id : string ) : Droid {
146
+ export function getDroid ( id : string ) : DroidData {
160
147
return droidData [ id ] ;
161
148
}
0 commit comments