Skip to content

Commit 4c487bc

Browse files
committed
fix(generator): use renderName for scalar types to escape TypeScript reserved keywords
Fixes scalar type generation to properly escape TypeScript reserved keywords like 'bigint' by using the existing renderName() function. This prevents compilation errors when GraphQL schemas contain scalars with reserved names. Fixes #1354
1 parent b5c643d commit 4c487bc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/generator/generators/Scalar.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Grafaid } from '../../lib/grafaid/_namespace.js'
33
import { Tex } from '../../lib/tex/_namespace.js'
44
import { $ } from '../helpers/identifiers.js'
55
import { createModuleGenerator } from '../helpers/moduleGenerator.js'
6-
import { typeTitle2 } from '../helpers/render.js'
6+
import { renderName, typeTitle2 } from '../helpers/render.js'
77

88
export const ModuleGeneratorScalar = createModuleGenerator(
99
`scalar`,
@@ -32,12 +32,12 @@ export const ModuleGeneratorScalar = createModuleGenerator(
3232
code(typeTitle2(`custom scalar type`)(scalar))
3333
code``
3434
code`
35-
export type ${scalar.name} = typeof ${$.CustomScalars}.${scalar.name}
35+
export type ${renderName(scalar.name)} = typeof ${$.CustomScalars}.${scalar.name}
3636
// Without this we get error:
3737
// "Exported type alias 'DateDecoded' has or is using private name 'Date'."
38-
type ${scalar.name}_ = typeof ${$.CustomScalars}.${scalar.name}
39-
export type ${scalar.name}Decoded = ${$.$$Utilities}.Schema.Scalar.GetDecoded<${scalar.name}_>
40-
export type ${scalar.name}Encoded = ${$.$$Utilities}.Schema.Scalar.GetEncoded<${scalar.name}_>
38+
type ${renderName(scalar.name)}_ = typeof ${$.CustomScalars}.${scalar.name}
39+
export type ${renderName(scalar.name)}Decoded = ${$.$$Utilities}.Schema.Scalar.GetDecoded<${renderName(scalar.name)}_>
40+
export type ${renderName(scalar.name)}Encoded = ${$.$$Utilities}.Schema.Scalar.GetEncoded<${renderName(scalar.name)}_>
4141
`
4242
code``
4343
}
@@ -56,7 +56,7 @@ export const ModuleGeneratorScalar = createModuleGenerator(
5656
for (const scalar of config.schema.kindMap.list.ScalarCustom) {
5757
code(typeTitle2(`custom scalar type`)(scalar))
5858
code``
59-
code`export type ${scalar.name} = ${$.$$Utilities}.Schema.Scalar.ScalarCodecless<'${scalar.name}'>`
59+
code`export type ${renderName(scalar.name)} = ${$.$$Utilities}.Schema.Scalar.ScalarCodecless<'${scalar.name}'>`
6060
// code(`import type { String as ${scalar.name} } from '${config.paths.imports.grafflePackage.scalars}'`)
6161
// code()
6262
// code(`export { String as ${scalar.name} } from '${config.paths.imports.grafflePackage.scalars}'`)

0 commit comments

Comments
 (0)