From 58a58e88906cdc5657bede6a86716fd3bf7ff475 Mon Sep 17 00:00:00 2001 From: Nico Schett Date: Wed, 4 Dec 2024 11:58:23 +0100 Subject: [PATCH] fix(schema-parser): handle union types in input fields by defaulting to the first type This also fixes a issue where the inputs were not properly generated when they were optional and an array. --- .../pylon-builder/src/schema/schema-parser.ts | 53 ++++--------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/packages/pylon-builder/src/schema/schema-parser.ts b/packages/pylon-builder/src/schema/schema-parser.ts index e68700d..65f324b 100644 --- a/packages/pylon-builder/src/schema/schema-parser.ts +++ b/packages/pylon-builder/src/schema/schema-parser.ts @@ -803,51 +803,18 @@ export class SchemaParser { ]) }) } else { - let properties = getPublicPropertiesOfType( - this.checker, - type.getNonNullableType() - ) - - if (properties.length === 0) { - //get first union type of non nullable type - const nt = type.getNonNullableType() - if (nt.isUnion()) { - properties = getPublicPropertiesOfType(this.checker, nt.types[0]!) - } - } - - if (properties.length > 0) { - if (!referenceSchema[processing].has(type)) { - referenceSchema[processing].set(type, {}) - } + const firstType = type.types[0] - // Go through all properties of the union type and add them to the reference schema - properties.forEach(property => { - const propertyType = this.checker.getTypeOfSymbolAtLocation( - property, - this.sfiFile - ) + consola.warn( + `Warning: Union types in input fields are not supported yet. Defaulting to the first type (${this.checker.typeToString( + firstType + )}) at path: ${path.join(' > ')}` + ) - if (!isFunction(propertyType)) { - referenceSchema[processing].get(type)![ - property.escapedName as string - ] = { - returnType: propertyType, - args: {} - } - - recLoop( - propertyType, - { - propetyName: property.escapedName as string, - parentType: type - }, - processing, - [...path, property.escapedName as string] - ) - } - }) - } + recLoop(firstType.getNonNullableType(), info, processing, [ + ...path, + 'NON_NULLABLE' + ]) } } else if (isFunction(type)) { // skip fn for inputs