Skip to content

Commit

Permalink
fix: type check
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-scheers-lemon committed Oct 22, 2024
1 parent e3eadd3 commit a76305e
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any>[] {
private validateUnionClasses(params: TypeMetadata[]): boolean {
return params.every(
(typeMetadata) => typeMetadata.typeGroup === 'Class' && typeMetadata.type && !isExternalType(typeMetadata)
)
}

private getUnionClasses(typeMetadata: TypeMetadata): GraphQLObjectType<any, any>[] {
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 {
Expand Down

0 comments on commit a76305e

Please sign in to comment.