Skip to content

Commit 80a7af0

Browse files
committed
Ensure star wars example is following best practice
For example, resolveType must not return null.
1 parent 0b8bbda commit 80a7af0

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

src/__tests__/starWarsData.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,7 @@ var droidData = {
8989
*/
9090
function getCharacter(id) {
9191
// Returning a promise just to illustrate GraphQL.js's support.
92-
return new Promise(resolve => {
93-
if (humanData[id] !== undefined) {
94-
return resolve(humanData[id]);
95-
}
96-
if (droidData[id] !== undefined) {
97-
return resolve(droidData[id]);
98-
}
99-
return resolve(null);
100-
});
92+
return Promise.resolve(humanData[id] || droidData[id]);
10193
}
10294

10395
/**

src/__tests__/starWarsSchema.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,7 @@ var characterInterface = new GraphQLInterfaceType({
127127
},
128128
}),
129129
resolveType: (obj) => {
130-
if (starWarsData.Humans[obj.id] !== undefined) {
131-
return humanType;
132-
}
133-
if (starWarsData.Droids[obj.id] !== undefined) {
134-
return droidType;
135-
}
136-
return null;
130+
return starWarsData.Humans[obj.id] ? humanType : droidType;
137131
}
138132
});
139133

0 commit comments

Comments
 (0)