From 78540896bc4b03986891c48afae5edbd686a03f1 Mon Sep 17 00:00:00 2001 From: SeungRyeol Lee Date: Fri, 19 Sep 2025 23:57:56 +0900 Subject: [PATCH] feat(graphql): support one of input objects --- packages/graphql/lib/decorators/input-type.decorator.ts | 6 ++++++ .../factories/input-type-definition.factory.ts | 1 + .../graphql/lib/schema-builder/metadata/class.metadata.ts | 1 + 3 files changed, 8 insertions(+) diff --git a/packages/graphql/lib/decorators/input-type.decorator.ts b/packages/graphql/lib/decorators/input-type.decorator.ts index 5ee9960c0..e37864bd3 100644 --- a/packages/graphql/lib/decorators/input-type.decorator.ts +++ b/packages/graphql/lib/decorators/input-type.decorator.ts @@ -25,6 +25,11 @@ export interface InputTypeOptions { * If `true`, type will not be registered in the schema. */ isAbstract?: boolean; + /** + * If 'true', the input type will be '@oneOf' type. + * More info about '@oneOf' types in the [GraphQL spec](https://spec.graphql.org/September2025/#sec-OneOf-Input-Objects). + */ + isOneOf?: boolean; } /** @@ -67,6 +72,7 @@ export function InputType( name: name || target.name, description: options.description, isAbstract: options.isAbstract, + isOneOf: options.isOneOf, }; LazyMetadataStorage.store(() => TypeMetadataStorage.addInputTypeMetadata(metadata), diff --git a/packages/graphql/lib/schema-builder/factories/input-type-definition.factory.ts b/packages/graphql/lib/schema-builder/factories/input-type-definition.factory.ts index 788a3ba76..dac52d8a3 100644 --- a/packages/graphql/lib/schema-builder/factories/input-type-definition.factory.ts +++ b/packages/graphql/lib/schema-builder/factories/input-type-definition.factory.ts @@ -34,6 +34,7 @@ export class InputTypeDefinitionFactory { type: new GraphQLInputObjectType({ name: metadata.name, description: metadata.description, + isOneOf: metadata.isOneOf, fields: this.generateFields(metadata, options), /** * AST node has to be manually created in order to define directives diff --git a/packages/graphql/lib/schema-builder/metadata/class.metadata.ts b/packages/graphql/lib/schema-builder/metadata/class.metadata.ts index 044a70268..4ff8f3d7d 100644 --- a/packages/graphql/lib/schema-builder/metadata/class.metadata.ts +++ b/packages/graphql/lib/schema-builder/metadata/class.metadata.ts @@ -10,4 +10,5 @@ export interface ClassMetadata { extensions?: Record; properties?: PropertyMetadata[]; inheritDescription?: boolean; + isOneOf?: boolean; // For '@oneOf' input types }