diff --git a/packages/graphql/lib/interfaces/build-schema-options.interface.ts b/packages/graphql/lib/interfaces/build-schema-options.interface.ts index 0b0507461..9792e9700 100644 --- a/packages/graphql/lib/interfaces/build-schema-options.interface.ts +++ b/packages/graphql/lib/interfaces/build-schema-options.interface.ts @@ -27,6 +27,12 @@ export interface BuildSchemaOptions { */ scalarsMap?: ScalarsTypeMap[]; + /** + * Whether or not to register all detected orphaned types in the schema + * @default true + */ + autoRegisterOrphanedTypes?: boolean; + /** * Orphaned type classes/enums that are not explicitly used in GraphQL types definitions */ diff --git a/packages/graphql/lib/schema-builder/factories/orphaned-types.factory.ts b/packages/graphql/lib/schema-builder/factories/orphaned-types.factory.ts index 2788ab895..ed1420c24 100644 --- a/packages/graphql/lib/schema-builder/factories/orphaned-types.factory.ts +++ b/packages/graphql/lib/schema-builder/factories/orphaned-types.factory.ts @@ -12,8 +12,14 @@ export class OrphanedTypesFactory { private readonly orphanedReferenceRegistry: OrphanedReferenceRegistry, ) {} - public create(types: (Function | object)[]): GraphQLNamedType[] { - types = (types || []).concat(this.orphanedReferenceRegistry.getAll()); + public create( + types: (Function | object)[], + useRegistry: boolean, + ): GraphQLNamedType[] { + types = types || []; + if (useRegistry) { + types = types.concat(this.orphanedReferenceRegistry.getAll()); + } if (types.length === 0) { return []; diff --git a/packages/graphql/lib/schema-builder/graphql-schema.factory.ts b/packages/graphql/lib/schema-builder/graphql-schema.factory.ts index 55db1d34e..067cf3348 100644 --- a/packages/graphql/lib/schema-builder/graphql-schema.factory.ts +++ b/packages/graphql/lib/schema-builder/graphql-schema.factory.ts @@ -70,7 +70,10 @@ export class GraphQLSchemaFactory { query: this.queryTypeFactory.create(resolvers, options), subscription: this.subscriptionTypeFactory.create(resolvers, options), types: [ - ...this.orphanedTypesFactory.create(options.orphanedTypes), + ...this.orphanedTypesFactory.create( + options.orphanedTypes, + options.autoRegisterOrphanedTypes ?? true, + ), ...(options.scalarsMap ?? []).map(({ scalar }) => scalar), ], directives: [...specifiedDirectives, ...(options.directives ?? [])],