Skip to content

Commit

Permalink
GraphQLSchema: simplify getPossibleTypes & isPossibleType (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Aug 13, 2019
1 parent d9f959e commit d78b445
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/type/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
type GraphQLNamedType,
type GraphQLAbstractType,
type GraphQLObjectType,
isAbstractType,
isObjectType,
isInterfaceType,
isUnionType,
Expand Down Expand Up @@ -202,8 +201,6 @@ export class GraphQLSchema {
}
}
}
} else if (isAbstractType(type) && !this._implementations[type.name]) {
this._implementations[type.name] = [];
}
}
}
Expand Down Expand Up @@ -234,24 +231,22 @@ export class GraphQLSchema {
if (isUnionType(abstractType)) {
return abstractType.getTypes();
}
return this._implementations[abstractType.name];
return this._implementations[abstractType.name] || [];
}

isPossibleType(
abstractType: GraphQLAbstractType,
possibleType: GraphQLObjectType,
): boolean {
const possibleTypeMap = this._possibleTypeMap;

if (!possibleTypeMap[abstractType.name]) {
const possibleTypes = this.getPossibleTypes(abstractType);
possibleTypeMap[abstractType.name] = possibleTypes.reduce((map, type) => {
if (this._possibleTypeMap[abstractType.name] == null) {
const map = Object.create(null);
for (const type of this.getPossibleTypes(abstractType)) {
map[type.name] = true;
return map;
}, Object.create(null));
}
this._possibleTypeMap[abstractType.name] = map;
}

return Boolean(possibleTypeMap[abstractType.name][possibleType.name]);
return Boolean(this._possibleTypeMap[abstractType.name][possibleType.name]);
}

getDirectives(): $ReadOnlyArray<GraphQLDirective> {
Expand Down

0 comments on commit d78b445

Please sign in to comment.