Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQLSchema: simplify getPossibleTypes & isPossibleType #2086

Merged
merged 1 commit into from Aug 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/type/schema.js
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