From a76305e383952eac4e4c540fdb5ad0429e8bd97c Mon Sep 17 00:00:00 2001 From: Nicolas Scheers Date: Tue, 22 Oct 2024 10:03:15 +0200 Subject: [PATCH] fix: type check --- .../services/graphql/graphql-type-informer.ts | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/framework-core/src/services/graphql/graphql-type-informer.ts b/packages/framework-core/src/services/graphql/graphql-type-informer.ts index 4754d35ff..1336ed725 100644 --- a/packages/framework-core/src/services/graphql/graphql-type-informer.ts +++ b/packages/framework-core/src/services/graphql/graphql-type-informer.ts @@ -88,23 +88,30 @@ export class GraphQLTypeInformer { const metadata = getClassMetadata(typeMetadata.type) return this.createObjectType(metadata, inputType) } - if (typeMetadata.typeGroup === 'Union' && !isExternalType(typeMetadata)) { - try { - const graphQLUnionClasses: GraphQLObjectType[] = this.getUnionClasses(typeMetadata, inputType) - return new GraphQLUnionType({ - name: typeMetadata.name, - types: graphQLUnionClasses, - }) - } catch (e) { - console.error(e) //Todo dit is raar - } + if ( + typeMetadata.typeGroup === 'Union' && + !isExternalType(typeMetadata) && + !inputType && + this.validateUnionClasses(typeMetadata.parameters) + ) { + const graphQLUnionClasses: GraphQLObjectType[] = this.getUnionClasses(typeMetadata) + return new GraphQLUnionType({ + name: typeMetadata.name, + types: graphQLUnionClasses, + }) } return GraphQLJSON } - private getUnionClasses(typeMetadata: TypeMetadata, inputType: boolean): GraphQLObjectType[] { + private validateUnionClasses(params: TypeMetadata[]): boolean { + return params.every( + (typeMetadata) => typeMetadata.typeGroup === 'Class' && typeMetadata.type && !isExternalType(typeMetadata) + ) + } + + private getUnionClasses(typeMetadata: TypeMetadata): GraphQLObjectType[] { return typeMetadata.parameters.map((param: TypeMetadata) => { - if (param.typeGroup === 'Class' && param.type && !isExternalType(typeMetadata) && !inputType) { + if (param.typeGroup === 'Class' && param.type && !isExternalType(typeMetadata)) { const metadata = getClassMetadata(param.type) return this.createObjectTypeForUnion(metadata) as GraphQLObjectType } else {