Skip to content

Commit

Permalink
feat(schema-builder): update OrphanedTypesFactory.create to include e…
Browse files Browse the repository at this point in the history
…nums

resolve #1665
  • Loading branch information
greatSumini committed Oct 30, 2021
1 parent 6fe2556 commit 7562228
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/schema-builder/factories/orphaned-types.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class OrphanedTypesFactory {
private readonly orphanedReferenceRegistry: OrphanedReferenceRegistry,
) {}

public create(types: Function[]): GraphQLNamedType[] {
public create(types: (Function | object)[]): GraphQLNamedType[] {
types = (types || []).concat(this.orphanedReferenceRegistry.getAll());

if (types.length === 0) {
Expand All @@ -26,14 +26,23 @@ export class OrphanedTypesFactory {
...objectTypeDefs,
...inputTypeDefs,
];
return classTypeDefs
.filter((item) => !item.isAbstract)
.filter((item: ObjectTypeDefinition) => {
const implementsReferencedInterface = getInterfacesArray(
item.interfaces,
).some((i) => types.includes(i));
return types.includes(item.target) || implementsReferencedInterface;
})
.map(({ type }) => type);

const enumTypeDefs =
this.typeDefinitionsStorage.getAllEnumTypeDefinitions();

return [
...classTypeDefs
.filter((item) => !item.isAbstract)
.filter((item: ObjectTypeDefinition) => {
const implementsReferencedInterface = getInterfacesArray(
item.interfaces,
).some((i) => types.includes(i));
return types.includes(item.target) || implementsReferencedInterface;
})
.map(({ type }) => type),
...enumTypeDefs
.filter((item) => types.includes(item.enumRef))
.map(({ type }) => type),
];
}
}

0 comments on commit 7562228

Please sign in to comment.