Skip to content

Commit d78b445

Browse files
GraphQLSchema: simplify getPossibleTypes & isPossibleType (#2086)
1 parent d9f959e commit d78b445

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/type/schema.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
type GraphQLNamedType,
2828
type GraphQLAbstractType,
2929
type GraphQLObjectType,
30-
isAbstractType,
3130
isObjectType,
3231
isInterfaceType,
3332
isUnionType,
@@ -202,8 +201,6 @@ export class GraphQLSchema {
202201
}
203202
}
204203
}
205-
} else if (isAbstractType(type) && !this._implementations[type.name]) {
206-
this._implementations[type.name] = [];
207204
}
208205
}
209206
}
@@ -234,24 +231,22 @@ export class GraphQLSchema {
234231
if (isUnionType(abstractType)) {
235232
return abstractType.getTypes();
236233
}
237-
return this._implementations[abstractType.name];
234+
return this._implementations[abstractType.name] || [];
238235
}
239236

240237
isPossibleType(
241238
abstractType: GraphQLAbstractType,
242239
possibleType: GraphQLObjectType,
243240
): boolean {
244-
const possibleTypeMap = this._possibleTypeMap;
245-
246-
if (!possibleTypeMap[abstractType.name]) {
247-
const possibleTypes = this.getPossibleTypes(abstractType);
248-
possibleTypeMap[abstractType.name] = possibleTypes.reduce((map, type) => {
241+
if (this._possibleTypeMap[abstractType.name] == null) {
242+
const map = Object.create(null);
243+
for (const type of this.getPossibleTypes(abstractType)) {
249244
map[type.name] = true;
250-
return map;
251-
}, Object.create(null));
245+
}
246+
this._possibleTypeMap[abstractType.name] = map;
252247
}
253248

254-
return Boolean(possibleTypeMap[abstractType.name][possibleType.name]);
249+
return Boolean(this._possibleTypeMap[abstractType.name][possibleType.name]);
255250
}
256251

257252
getDirectives(): $ReadOnlyArray<GraphQLDirective> {

0 commit comments

Comments
 (0)