Skip to content

Commit b3d36c9

Browse files
authored
fix: use renderName for scalar types to escape TypeScript reserved keywords (#1363)
1 parent b5c643d commit b3d36c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+10864
-19
lines changed

examples/$/graffle/modules/data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const Name = `default`
2+
23
export type Name = 'default'
34

45
export const defaultSchemaUrl = new URL('http://localhost:3000/graphql')

examples/$/graffle/modules/scalar.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type * as $$Utilities from 'graffle/utilities-for-generated'
2-
32
export * from 'graffle/generator-helpers/standard-scalar-types'
43

54
//

examples/$/graffle/modules/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as $$SelectionSets from './selection-sets.js'
1919
//
2020
//
2121
//
22+
2223
import { createSelect } from 'graffle/client'
2324
export const Select = createSelect($$Data.Name)
2425

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"scripts": {
5959
"extension:document-builder:test:generate-fixtures": "tsx src/extensions/DocumentBuilder/__tests__/fixtures/generate.ts",
6060
"extension:schema-errors:test:generate-fixtures": "pnpm graffle --project src/extensions/SchemaErrors/__tests__/fixture",
61-
"graffle": "tsx ./src/generator/cli/generate.ts",
61+
"graffle": "tsx ./src/cli/index.ts",
6262
"serve:pokemon": "tsx tests/_/services/pokemonManual.ts",
6363
"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",
6464
"examples:gen:graffle": "pnpm build && cd examples && pnpm i && pnpm gen:graffle",

src/extensions/DocumentBuilder/__tests__/fixtures/possible-with-scalars/modules/methods-root.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,40 @@ export interface QueryMethods<$Context extends $$Utilities.Context> {
106106
>
107107
>
108108

109+
bigintField: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
110+
$Context,
111+
<$SelectionSet>(
112+
selectionSet?: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.bigintField<$Context['scalars']>>,
113+
) => Promise<
114+
& (null | {})
115+
& $$Utilities.HandleOutputDocumentBuilderRootField<
116+
$Context,
117+
$$Utilities.DocumentBuilderKit.InferResult.OperationQuery<
118+
{ bigintField: $SelectionSet },
119+
$$Schema.Schema<$Context['scalars']>
120+
>,
121+
'bigintField'
122+
>
123+
>
124+
>
125+
126+
bigintFieldNonNull: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
127+
$Context,
128+
<$SelectionSet>(
129+
selectionSet?: $$Utilities.Exact<$SelectionSet, $$SelectionSets.Query.bigintFieldNonNull<$Context['scalars']>>,
130+
) => Promise<
131+
& (null | {})
132+
& $$Utilities.HandleOutputDocumentBuilderRootField<
133+
$Context,
134+
$$Utilities.DocumentBuilderKit.InferResult.OperationQuery<
135+
{ bigintFieldNonNull: $SelectionSet },
136+
$$Schema.Schema<$Context['scalars']>
137+
>,
138+
'bigintFieldNonNull'
139+
>
140+
>
141+
>
142+
109143
date: $$Utilities.GraffleKit.Context.Configuration.Check.Preflight<
110144
$Context,
111145
<$SelectionSet>(

src/extensions/DocumentBuilder/__tests__/fixtures/possible-with-scalars/modules/scalar.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ type Date_ = typeof CustomScalars.Date
2121
export type DateDecoded = $$Utilities.Schema.Scalar.GetDecoded<Date_>
2222
export type DateEncoded = $$Utilities.Schema.Scalar.GetEncoded<Date_>
2323

24+
//
25+
//
26+
//
27+
//
28+
// CUSTOM SCALAR TYPE
29+
// BIGINT
30+
// --------------------------------------------------------------------------------------------------
31+
// bigint
32+
// --------------------------------------------------------------------------------------------------
33+
//
34+
//
35+
36+
export type $bigint = typeof CustomScalars.bigint
37+
// Without this we get error:
38+
// "Exported type alias 'DateDecoded' has or is using private name 'Date'."
39+
type $bigint_ = typeof CustomScalars.bigint
40+
export type $bigintDecoded = $$Utilities.Schema.Scalar.GetDecoded<$bigint_>
41+
export type $bigintEncoded = $$Utilities.Schema.Scalar.GetEncoded<$bigint_>
42+
2443
export * from '../../../../../../types/Schema/StandardTypes/scalar.js'
2544

2645
//
@@ -42,13 +61,17 @@ export * from '../../../../../../types/Schema/StandardTypes/scalar.js'
4261
export const $registry = {
4362
map: {
4463
Date: CustomScalars.Date,
64+
bigint: CustomScalars.bigint,
4565
},
4666
} as $Registry
4767

4868
export type $Registry = $$Utilities.Schema.Scalar.Registry<
4969
{
5070
Date: Date_
71+
bigint: bigint_
5172
},
52-
$$Utilities.Schema.Scalar.GetEncoded<Date_>,
53-
$$Utilities.Schema.Scalar.GetDecoded<Date_>
73+
| $$Utilities.Schema.Scalar.GetEncoded<Date_>
74+
| $$Utilities.Schema.Scalar.GetEncoded<bigint_>,
75+
| $$Utilities.Schema.Scalar.GetDecoded<Date_>
76+
| $$Utilities.Schema.Scalar.GetDecoded<bigint_>
5477
>

src/extensions/DocumentBuilder/__tests__/fixtures/possible-with-scalars/modules/schema-driven-data-map.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const String = $$Scalar.String
4444

4545
const Date = $$Scalar.Date
4646

47+
const bigint = $$Scalar.$bigint
48+
4749
//
4850
//
4951
//
@@ -431,6 +433,12 @@ const Query: $$Utilities.SchemaDrivenDataMap.OutputObject = {
431433
},
432434
},
433435
},
436+
bigintField: {
437+
nt: bigint,
438+
},
439+
bigintFieldNonNull: {
440+
nt: bigint,
441+
},
434442
date: {
435443
nt: Date,
436444
},
@@ -823,6 +831,7 @@ const $schemaDrivenDataMap: $$Utilities.SchemaDrivenDataMap = {
823831
Int,
824832
String,
825833
Date,
834+
bigint,
826835
ABCEnum,
827836
Case,
828837
ChildAInterfaceHierarchyMember,

src/extensions/DocumentBuilder/__tests__/fixtures/possible-with-scalars/modules/schema.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export namespace Schema {
3333
InputObjectNestedNonNull: Query.InputObjectNestedNonNull
3434
abcEnum: Query.abcEnum
3535
argInputObjectCircular: Query.argInputObjectCircular
36+
bigintField: Query.bigintField
37+
bigintFieldNonNull: Query.bigintFieldNonNull
3638
date: Query.date
3739
dateArg: Query.dateArg
3840
dateArgInputObject: Query.dateArgInputObject
@@ -155,6 +157,22 @@ export namespace Schema {
155157
namedType: $$NamedTypes.$$String
156158
}
157159

160+
export interface bigintField extends $.OutputField {
161+
kind: 'OutputField'
162+
name: 'bigintField'
163+
arguments: {}
164+
inlineType: [0]
165+
namedType: $$NamedTypes.$$bigint
166+
}
167+
168+
export interface bigintFieldNonNull extends $.OutputField {
169+
kind: 'OutputField'
170+
name: 'bigintFieldNonNull'
171+
arguments: {}
172+
inlineType: [1]
173+
namedType: $$NamedTypes.$$bigint
174+
}
175+
158176
export interface date extends $.OutputField {
159177
kind: 'OutputField'
160178
name: 'date'
@@ -2348,6 +2366,12 @@ export namespace Schema {
23482366

23492367
export type Date = $$Scalar.Date
23502368

2369+
// bigint
2370+
// --------------------------------------------------------------------------------------------------
2371+
//
2372+
2373+
export type $bigint = $$Scalar.$bigint
2374+
23512375
//
23522376
//
23532377
//
@@ -2461,6 +2485,7 @@ export namespace Schema {
24612485
export type $$GrandparentInterfaceHierarchyMember = GrandparentInterfaceHierarchyMember
24622486
export type $$ParentInterfaceHierarchyMember = ParentInterfaceHierarchyMember
24632487
export type $$Date = Date
2488+
export type $$bigint = $bigint
24642489
export type $$Boolean = Boolean
24652490
export type $$Float = Float
24662491
export type $$ID = ID
@@ -2570,13 +2595,15 @@ export interface Schema<$Scalars extends $$Utilities.Schema.Scalar.Registry = $$
25702595
}
25712596
scalarNamesUnion:
25722597
| 'Date'
2598+
| 'bigint'
25732599
| 'Boolean'
25742600
| 'Float'
25752601
| 'ID'
25762602
| 'Int'
25772603
| 'String'
25782604
scalars: {
25792605
Date: Schema.Date
2606+
bigint: Schema.$bigint
25802607
Boolean: Schema.Boolean
25812608
Float: Schema.Float
25822609
ID: Schema.ID

src/extensions/DocumentBuilder/__tests__/fixtures/possible-with-scalars/modules/selection-sets.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ export interface Query<
7272
argInputObjectCircular?:
7373
| Query.argInputObjectCircular$Expanded<_$Scalars>
7474
| $$Utilities.DocumentBuilderKit.Select.SelectAlias.SelectAlias<Query.argInputObjectCircular<_$Scalars>>
75+
/**
76+
* Select the `bigintField` field on the `Query` object. Its type is `bigint` (a `ScalarCustom` kind of type).
77+
*/
78+
bigintField?:
79+
| Query.bigintField$Expanded<_$Scalars>
80+
| $$Utilities.DocumentBuilderKit.Select.SelectAlias.SelectAlias<Query.bigintField<_$Scalars>>
81+
/**
82+
* Select the `bigintFieldNonNull` field on the `Query` object. Its type is `bigint` (a `ScalarCustom` kind of type).
83+
*/
84+
bigintFieldNonNull?:
85+
| Query.bigintFieldNonNull$Expanded<_$Scalars>
86+
| $$Utilities.DocumentBuilderKit.Select.SelectAlias.SelectAlias<Query.bigintFieldNonNull<_$Scalars>>
7587
/**
7688
* Select the `date` field on the `Query` object. Its type is `Date` (a `ScalarCustom` kind of type).
7789
*/
@@ -541,6 +553,58 @@ export namespace Query {
541553

542554
// --------------------------------------------------------------------------------------------------
543555

556+
export type bigintField<
557+
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
558+
> =
559+
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
560+
| bigintField$SelectionSet<_$Scalars>
561+
562+
export interface bigintField$SelectionSet<
563+
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
564+
> extends $$Utilities.DocumentBuilderKit.Select.Bases.Base {}
565+
566+
// --- expanded ---
567+
568+
/**
569+
* This is the "expanded" version of the `bigintField` type. It is identical except for the fact
570+
* that IDEs will display its contents (a union type) directly, rather than the name of this type.
571+
* In some cases, this is a preferable DX, making the types easier to read for users.
572+
*/
573+
export type bigintField$Expanded<
574+
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
575+
> = $$Utilities.Simplify<
576+
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
577+
| bigintField$SelectionSet<_$Scalars>
578+
>
579+
580+
// --------------------------------------------------------------------------------------------------
581+
582+
export type bigintFieldNonNull<
583+
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
584+
> =
585+
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
586+
| bigintFieldNonNull$SelectionSet<_$Scalars>
587+
588+
export interface bigintFieldNonNull$SelectionSet<
589+
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
590+
> extends $$Utilities.DocumentBuilderKit.Select.Bases.Base {}
591+
592+
// --- expanded ---
593+
594+
/**
595+
* This is the "expanded" version of the `bigintFieldNonNull` type. It is identical except for the fact
596+
* that IDEs will display its contents (a union type) directly, rather than the name of this type.
597+
* In some cases, this is a preferable DX, making the types easier to read for users.
598+
*/
599+
export type bigintFieldNonNull$Expanded<
600+
_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty,
601+
> = $$Utilities.Simplify<
602+
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
603+
| bigintFieldNonNull$SelectionSet<_$Scalars>
604+
>
605+
606+
// --------------------------------------------------------------------------------------------------
607+
544608
export type date<_$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty> =
545609
| $$Utilities.DocumentBuilderKit.Select.Indicator.NoArgsIndicator
546610
| date$SelectionSet<_$Scalars>

src/extensions/DocumentBuilder/__tests__/fixtures/possible-with-scalars/schema.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ type Query {
195195
"""Query enum field documentation."""
196196
abcEnum: ABCEnum
197197
argInputObjectCircular(input: InputObjectCircular): String
198+
bigintField: bigint
199+
bigintFieldNonNull: bigint!
198200
date: Date
199201
dateArg(date: Date): Date
200202
dateArgInputObject(input: InputObject): Date
@@ -260,6 +262,8 @@ type Query {
260262

261263
union Result = ErrorOne | ErrorTwo | Object1
262264

265+
scalar bigint
266+
263267
type lowerCaseObject {
264268
id: ID
265269
}

0 commit comments

Comments
 (0)