Skip to content

feat: add option to disable automatic orphan registration #3528

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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