Skip to content

fix: use renderName for scalar types to escape TypeScript reserved keywords #1363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/$/graffle/modules/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const Name = `default`

export type Name = 'default'

export const defaultSchemaUrl = new URL('http://localhost:3000/graphql')
1 change: 0 additions & 1 deletion examples/$/graffle/modules/scalar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type * as $$Utilities from 'graffle/utilities-for-generated'

export * from 'graffle/generator-helpers/standard-scalar-types'

//
Expand Down
1 change: 1 addition & 0 deletions examples/$/graffle/modules/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as $$SelectionSets from './selection-sets.js'
//
//
//

import { createSelect } from 'graffle/client'
export const Select = createSelect($$Data.Name)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"scripts": {
"extension:document-builder:test:generate-fixtures": "tsx src/extensions/DocumentBuilder/__tests__/fixtures/generate.ts",
"extension:schema-errors:test:generate-fixtures": "pnpm graffle --project src/extensions/SchemaErrors/__tests__/fixture",
"graffle": "tsx ./src/generator/cli/generate.ts",
"graffle": "tsx ./src/cli/index.ts",
"serve:pokemon": "tsx tests/_/services/pokemonManual.ts",
"gen:graffle": "pnpm test:e2e:github:gen:graffle && pnpm extension:schema-errors:test:generate-fixtures && pnpm extension:document-builder:test:generate-fixtures && pnpm website:gen:graffle",
"examples:gen:graffle": "pnpm build && cd examples && pnpm i && pnpm gen:graffle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ export interface QueryMethods<$Context extends $$Utilities.Context> {
>
>

bigintField: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
$Context,
<$SelectionSet>(
selectionSet?: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.bigintField<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputDocumentBuilderRootField<
$Context,
$$Utilities.DocumentBuilderKit.InferResult.OperationQuery<
{ bigintField: $SelectionSet },
$$Schema.Schema<$Context['scalars']>
>,
'bigintField'
>
>
>

bigintFieldNonNull: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
$Context,
<$SelectionSet>(
selectionSet?: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.bigintFieldNonNull<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputDocumentBuilderRootField<
$Context,
$$Utilities.DocumentBuilderKit.InferResult.OperationQuery<
{ bigintFieldNonNull: $SelectionSet },
$$Schema.Schema<$Context['scalars']>
>,
'bigintFieldNonNull'
>
>
>

date: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
$Context,
<$SelectionSet>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ type Date_ = typeof CustomScalars.Date
export type DateDecoded = $$Utilities.Schema.Scalar.GetDecoded<Date_>
export type DateEncoded = $$Utilities.Schema.Scalar.GetEncoded<Date_>

//
//
//
//
// CUSTOM SCALAR TYPE
// BIGINT
// --------------------------------------------------------------------------------------------------
// bigint
// --------------------------------------------------------------------------------------------------
//
//

export type $bigint = typeof CustomScalars.bigint
// Without this we get error:
// "Exported type alias 'DateDecoded' has or is using private name 'Date'."
type $bigint_ = typeof CustomScalars.bigint
export type $bigintDecoded = $$Utilities.Schema.Scalar.GetDecoded<$bigint_>
export type $bigintEncoded = $$Utilities.Schema.Scalar.GetEncoded<$bigint_>

export * from '../../../../../../types/Schema/StandardTypes/scalar.js'

//
Expand All @@ -42,13 +61,17 @@ export * from '../../../../../../types/Schema/StandardTypes/scalar.js'
export const $registry = {
map: {
Date: CustomScalars.Date,
bigint: CustomScalars.bigint,
},
} as $Registry

export type $Registry = $$Utilities.Schema.Scalar.Registry<
{
Date: Date_
bigint: bigint_
},
$$Utilities.Schema.Scalar.GetEncoded<Date_>,
$$Utilities.Schema.Scalar.GetDecoded<Date_>
| $$Utilities.Schema.Scalar.GetEncoded<Date_>
| $$Utilities.Schema.Scalar.GetEncoded<bigint_>,
| $$Utilities.Schema.Scalar.GetDecoded<Date_>
| $$Utilities.Schema.Scalar.GetDecoded<bigint_>
>
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const String = $$Scalar.String

const Date = $$Scalar.Date

const bigint = $$Scalar.$bigint

//
//
//
Expand Down Expand Up @@ -431,6 +433,12 @@ const Query: $$Utilities.SchemaDrivenDataMap.OutputObject = {
},
},
},
bigintField: {
nt: bigint,
},
bigintFieldNonNull: {
nt: bigint,
},
date: {
nt: Date,
},
Expand Down Expand Up @@ -823,6 +831,7 @@ const $schemaDrivenDataMap: $$Utilities.SchemaDrivenDataMap = {
Int,
String,
Date,
bigint,
ABCEnum,
Case,
ChildAInterfaceHierarchyMember,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export namespace Schema {
InputObjectNestedNonNull: Query.InputObjectNestedNonNull
abcEnum: Query.abcEnum
argInputObjectCircular: Query.argInputObjectCircular
bigintField: Query.bigintField
bigintFieldNonNull: Query.bigintFieldNonNull
date: Query.date
dateArg: Query.dateArg
dateArgInputObject: Query.dateArgInputObject
Expand Down Expand Up @@ -155,6 +157,22 @@ export namespace Schema {
namedType: $$NamedTypes.$$String
}

export interface bigintField extends $.OutputField {
kind: 'OutputField'
name: 'bigintField'
arguments: {}
inlineType: [0]
namedType: $$NamedTypes.$$bigint
}

export interface bigintFieldNonNull extends $.OutputField {
kind: 'OutputField'
name: 'bigintFieldNonNull'
arguments: {}
inlineType: [1]
namedType: $$NamedTypes.$$bigint
}

export interface date extends $.OutputField {
kind: 'OutputField'
name: 'date'
Expand Down Expand Up @@ -2348,6 +2366,12 @@ export namespace Schema {

export type Date = $$Scalar.Date

// bigint
// --------------------------------------------------------------------------------------------------
//

export type $bigint = $$Scalar.$bigint

//
//
//
Expand Down Expand Up @@ -2461,6 +2485,7 @@ export namespace Schema {
export type $$GrandparentInterfaceHierarchyMember = GrandparentInterfaceHierarchyMember
export type $$ParentInterfaceHierarchyMember = ParentInterfaceHierarchyMember
export type $$Date = Date
export type $$bigint = $bigint
export type $$Boolean = Boolean
export type $$Float = Float
export type $$ID = ID
Expand Down Expand Up @@ -2570,13 +2595,15 @@ export interface Schema<$Scalars extends $$Utilities.Schema.Scalar.Registry = $$
}
scalarNamesUnion:
| 'Date'
| 'bigint'
| 'Boolean'
| 'Float'
| 'ID'
| 'Int'
| 'String'
scalars: {
Date: Schema.Date
bigint: Schema.$bigint
Boolean: Schema.Boolean
Float: Schema.Float
ID: Schema.ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ export interface Query<
argInputObjectCircular?:
| Query.argInputObjectCircular$Expanded<_$Scalars>
| $$Utilities.DocumentBuilderKit.Select.SelectAlias.SelectAlias<Query.argInputObjectCircular<_$Scalars>>
/**
* Select the `bigintField` field on the `Query` object. Its type is `bigint` (a `ScalarCustom` kind of type).
*/
bigintField?:
| Query.bigintField$Expanded<_$Scalars>
| $$Utilities.DocumentBuilderKit.Select.SelectAlias.SelectAlias<Query.bigintField<_$Scalars>>
/**
* Select the `bigintFieldNonNull` field on the `Query` object. Its type is `bigint` (a `ScalarCustom` kind of type).
*/
bigintFieldNonNull?:
| Query.bigintFieldNonNull$Expanded<_$Scalars>
| $$Utilities.DocumentBuilderKit.Select.SelectAlias.SelectAlias<Query.bigintFieldNonNull<_$Scalars>>
/**
* Select the `date` field on the `Query` object. Its type is `Date` (a `ScalarCustom` kind of type).
*/
Expand Down Expand Up @@ -541,6 +553,58 @@ export namespace Query {

// --------------------------------------------------------------------------------------------------

export type bigintField<
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
> =
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
| bigintField$SelectionSet<_$Scalars>

export interface bigintField$SelectionSet<
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
> extends $$Utilities.DocumentBuilderKit.Select.Bases.Base {}

// --- expanded ---

/**
* This is the "expanded" version of the `bigintField` type. It is identical except for the fact
* that IDEs will display its contents (a union type) directly, rather than the name of this type.
* In some cases, this is a preferable DX, making the types easier to read for users.
*/
export type bigintField$Expanded<
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
> = $$Utilities.Simplify<
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
| bigintField$SelectionSet<_$Scalars>
>

// --------------------------------------------------------------------------------------------------

export type bigintFieldNonNull<
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
> =
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
| bigintFieldNonNull$SelectionSet<_$Scalars>

export interface bigintFieldNonNull$SelectionSet<
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
> extends $$Utilities.DocumentBuilderKit.Select.Bases.Base {}

// --- expanded ---

/**
* This is the "expanded" version of the `bigintFieldNonNull` type. It is identical except for the fact
* that IDEs will display its contents (a union type) directly, rather than the name of this type.
* In some cases, this is a preferable DX, making the types easier to read for users.
*/
export type bigintFieldNonNull$Expanded<
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
> = $$Utilities.Simplify<
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
| bigintFieldNonNull$SelectionSet<_$Scalars>
>

// --------------------------------------------------------------------------------------------------

export type date<_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty> =
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
| date$SelectionSet<_$Scalars>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ type Query {
"""Query enum field documentation."""
abcEnum: ABCEnum
argInputObjectCircular(input: InputObjectCircular): String
bigintField: bigint
bigintFieldNonNull: bigint!
date: Date
dateArg(date: Date): Date
dateArgInputObject(input: InputObject): Date
Expand Down Expand Up @@ -260,6 +262,8 @@ type Query {

union Result = ErrorOne | ErrorTwo | Object1

scalar bigint

type lowerCaseObject {
id: ID
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// We import the global module for good measure although it is not clear it is always needed.
// It at least helps with Twoslash wherein without this import here Twoslash will not include the global module.
// In real TypeScript projects it seems the global module is included automatically. But there could be certain tsconfig
// setups where this still indeed does help.
import './modules/global.js'

export { create } from './modules/client.js'
export { Name } from './modules/data.js'
export { schemaDrivenDataMap as schemaMap } from './modules/schema-driven-data-map.js'
export { Select } from './modules/select.js'
export * as SelectionSets from './modules/selection-sets.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as Graffle from './_exports.js'
export { schemaDrivenDataMap as schemaMap } from './modules/schema-driven-data-map.js'
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ export interface QueryMethods<$Context extends $$Utilities.Context> {
>
>

bigintField: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
$Context,
<$SelectionSet>(
selectionSet?: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.bigintField<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputDocumentBuilderRootField<
$Context,
$$Utilities.DocumentBuilderKit.InferResult.OperationQuery<
{ bigintField: $SelectionSet },
$$Schema.Schema<$Context['scalars']>
>,
'bigintField'
>
>
>

bigintFieldNonNull: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
$Context,
<$SelectionSet>(
selectionSet?: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.bigintFieldNonNull<$Context['scalars']>>,
) => Promise<
& (null | {})
& $$Utilities.HandleOutputDocumentBuilderRootField<
$Context,
$$Utilities.DocumentBuilderKit.InferResult.OperationQuery<
{ bigintFieldNonNull: $SelectionSet },
$$Schema.Schema<$Context['scalars']>
>,
'bigintFieldNonNull'
>
>
>

date: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
$Context,
<$SelectionSet>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DocumentBuilder } from 'graffle/extensions/document-builder'
import { TransportHttp } from 'graffle/extensions/transport-http'
import * as $$Utilities from 'graffle/utilities-for-generated'
import * as $$Data from './data.js'
import * as $$Scalar from './scalar.js'
import * as $$SchemaDrivenDataMap from './schema-driven-data-map.js'

const context = $$Utilities.pipe(
$$Utilities.contextEmpty,
ctx => $$Utilities.Extensions.addAndApplyMany(ctx, [TransportHttp, DocumentBuilder]),
ctx => $$Utilities.Transports.configureCurrentOrThrow(ctx, { url: $$Data.defaultSchemaUrl }),
ctx =>
$$Utilities.Configuration.add(ctx, {
schema: {
name: $$Data.Name,
map: $$SchemaDrivenDataMap.schemaDrivenDataMap,
},
}),
ctx => $$Utilities.Scalars.set(ctx, { scalars: $$Scalar.$registry }),
)

export const create = $$Utilities.createConstructorWithContext(context)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const Name = `default`

export type Name = 'default'

export const defaultSchemaUrl = undefined
Loading
Loading