Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? [])],
Expand Down