Skip to content

Commit

Permalink
fix: enhance union type / array handling in input fields
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn committed Dec 4, 2024
1 parent 871c6d0 commit 75398e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/pylon-builder/src/schema/schema-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,18 +823,19 @@ export class SchemaParser {
])
})
} else {
const firstType = type.types[0]
let firstType = type.getNonNullableType()

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 (firstType.isUnion() && !isPrimitive(firstType)) {
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(' > ')}`
)

recLoop(firstType.getNonNullableType(), info, processing, [
...path,
'NON_NULLABLE'
])
firstType = firstType.types[0]
}

recLoop(firstType, info, processing, [...path, 'NON_NULLABLE'])
}
}
} else if (isFunction(type)) {
Expand Down
9 changes: 9 additions & 0 deletions packages/pylon-builder/src/schema/types-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const isList = (checker: ts.TypeChecker, type: ts.Type) => {
typeNode.kind === ts.SyntaxKind.TupleType)
)

if (!is) {
// Check if type references an array
const isArray = type.getSymbol()?.getName() === 'Array'

if (isArray) {
return true
}
}

return is
}

Expand Down

1 comment on commit 75398e6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for pylon-docs ready!

✅ Preview
https://pylon-docs-9go144c3w-schettns-projects.vercel.app

Built with commit 75398e6.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.