Skip to content

Commit baa7452

Browse files
authored
fix: enum decoding (#1140)
1 parent 1bbc5dd commit baa7452

Some content is hidden

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

53 files changed

+1587
-697
lines changed

examples/$/generated-clients/pokemon/modules/MethodsRoot.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ export interface QueryMethods<$Config extends Utils.Config> {
2424
'Query'
2525
>
2626
>
27+
beings: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.beings>) => Promise<
28+
Utils.ResolveOutputReturnRootField<
29+
$Config,
30+
Index,
31+
'beings',
32+
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['beings'], Index>
33+
>
34+
>
2735
pokemon: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.pokemon>) => Promise<
2836
Utils.ResolveOutputReturnRootField<
2937
$Config,

examples/$/generated-clients/pokemon/modules/MethodsSelect.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import type * as $SelectionSets from './SelectionSets.js'
2020
export interface $MethodsSelect {
2121
Mutation: Mutation
2222
Query: Query
23+
Patron: Patron
2324
Pokemon: Pokemon
2425
Trainer: Trainer
26+
Being: Being
2527
}
2628

2729
//
@@ -64,10 +66,34 @@ export interface Query {
6466
//
6567
//
6668

69+
export interface Patron {
70+
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Patron>): $SelectionSet
71+
}
72+
6773
export interface Pokemon {
6874
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Pokemon>): $SelectionSet
6975
}
7076

7177
export interface Trainer {
7278
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Trainer>): $SelectionSet
7379
}
80+
81+
//
82+
//
83+
//
84+
//
85+
//
86+
//
87+
// ==================================================================================================
88+
// Interface
89+
// ==================================================================================================
90+
//
91+
//
92+
//
93+
//
94+
//
95+
//
96+
97+
export interface Being {
98+
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Being>): $SelectionSet
99+
}

examples/$/generated-clients/pokemon/modules/SchemaBuildtime.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ export namespace Root {
99
addPokemon: $.Field<
1010
$.Output.Nullable<Object.Pokemon>,
1111
$.Args<{
12-
attack: $.Input.Field<$Scalar.Int>
13-
defense: $.Input.Field<$Scalar.Int>
14-
hp: $.Input.Field<$Scalar.Int>
12+
attack: $.Input.Field<$.Input.Nullable<$Scalar.Int>>
13+
defense: $.Input.Field<$.Input.Nullable<$Scalar.Int>>
14+
hp: $.Input.Field<$.Input.Nullable<$Scalar.Int>>
1515
name: $.Input.Field<$Scalar.String>
16+
type: $.Input.Field<Enum.PokemonType>
1617
}, false>
1718
>
1819
}>
1920

2021
export type Query = $.Output.ObjectQuery<{
22+
beings: $.Field<$.Output.List<Interface.Being>, null>
2123
pokemon: $.Field<$.Output.Nullable<$.Output.List<Object.Pokemon>>, null>
2224
pokemonByName: $.Field<
2325
$.Output.Nullable<$.Output.List<Object.Pokemon>>,
@@ -44,7 +46,26 @@ export namespace Root {
4446
// Enum //
4547
// ------------------------------------------------------------ //
4648
export namespace Enum {
47-
// -- no types --
49+
export type PokemonType = $.Enum<'PokemonType', ['electric', 'fire', 'grass', 'water']>
50+
51+
export type TrainerClass = $.Enum<
52+
'TrainerClass',
53+
[
54+
'bugCatcher',
55+
'camper',
56+
'picnicker',
57+
'psychic',
58+
'psychicMedium',
59+
'psychicYoungster',
60+
'sailor',
61+
'superNerd',
62+
'tamer',
63+
'teamRocketGrunt',
64+
'triathlete',
65+
'youngster',
66+
'youth',
67+
]
68+
>
4869
}
4970
// ------------------------------------------------------------ //
5071
// InputObject //
@@ -69,12 +90,21 @@ export namespace InputObject {
6990
// Interface //
7091
// ------------------------------------------------------------ //
7192
export namespace Interface {
72-
// -- no types --
93+
export type Being = $.Interface<'Being', {
94+
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
95+
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
96+
}, [Object.Patron, Object.Pokemon, Object.Trainer]>
7397
}
7498
// ------------------------------------------------------------ //
7599
// Object //
76100
// ------------------------------------------------------------ //
77101
export namespace Object {
102+
export type Patron = $.Object$2<'Patron', {
103+
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
104+
money: $.Field<$.Output.Nullable<$Scalar.Int>, null>
105+
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
106+
}>
107+
78108
export type Pokemon = $.Object$2<'Pokemon', {
79109
attack: $.Field<$.Output.Nullable<$Scalar.Int>, null>
80110
birthday: $.Field<$.Output.Nullable<$Scalar.Int>, null>
@@ -83,9 +113,12 @@ export namespace Object {
83113
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
84114
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
85115
trainer: $.Field<$.Output.Nullable<Object.Trainer>, null>
116+
type: $.Field<$.Output.Nullable<Enum.PokemonType>, null>
86117
}>
87118

88119
export type Trainer = $.Object$2<'Trainer', {
120+
class: $.Field<$.Output.Nullable<Enum.TrainerClass>, null>
121+
fans: $.Field<$.Output.Nullable<$.Output.List<Object.Patron>>, null>
89122
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
90123
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
91124
pokemon: $.Field<$.Output.Nullable<$.Output.List<Object.Pokemon>>, null>

examples/$/generated-clients/pokemon/modules/SchemaIndex.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@ export interface Index {
1515
allTypes: {
1616
Mutation: Schema.Root.Mutation
1717
Query: Schema.Root.Query
18+
PokemonType: Schema.Enum.PokemonType
19+
TrainerClass: Schema.Enum.TrainerClass
20+
Patron: Schema.Object.Patron
1821
Pokemon: Schema.Object.Pokemon
1922
Trainer: Schema.Object.Trainer
23+
Being: Schema.Interface.Being
2024
}
2125
objects: {
26+
Patron: Schema.Object.Patron
2227
Pokemon: Schema.Object.Pokemon
2328
Trainer: Schema.Object.Trainer
2429
}
2530
unions: {}
26-
interfaces: {}
31+
interfaces: {
32+
Being: Schema.Interface.Being
33+
}
2734
error: {
2835
objects: {}
2936
objectsTypename: {}

examples/$/generated-clients/pokemon/modules/SchemaRuntime.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ import * as Data from './Data.js'
44
import * as $Scalar from './Scalar.js'
55
import type { Index } from './SchemaIndex.js'
66
export const $defaultSchemaUrl = new URL('http://localhost:3000/graphql')
7-
7+
export const PokemonType = $.Enum(`PokemonType`, [`electric`, `fire`, `grass`, `water`])
8+
export const TrainerClass = $.Enum(`TrainerClass`, [
9+
`bugCatcher`,
10+
`camper`,
11+
`picnicker`,
12+
`psychic`,
13+
`psychicMedium`,
14+
`psychicYoungster`,
15+
`sailor`,
16+
`superNerd`,
17+
`tamer`,
18+
`teamRocketGrunt`,
19+
`triathlete`,
20+
`youngster`,
21+
`youth`,
22+
])
823
export const DateFilter = $.InputObject(`DateFilter`, {
924
gte: $.Input.Field($.Input.Nullable($Scalar.Float)),
1025
lte: $.Input.Field($.Input.Nullable($Scalar.Float)),
@@ -19,6 +34,13 @@ export const StringFilter = $.InputObject(`StringFilter`, {
1934
contains: $.Input.Field($.Input.Nullable($Scalar.String)),
2035
in: $.Input.Field($.Input.Nullable($.Input.List($Scalar.String))),
2136
}, true)
37+
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
38+
export const Patron = $.Object$(`Patron`, {
39+
id: $.field($.Output.Nullable($Scalar.Int)),
40+
money: $.field($.Output.Nullable($Scalar.Int)),
41+
name: $.field($.Output.Nullable($Scalar.String)),
42+
})
43+
2244
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
2345
export const Pokemon = $.Object$(`Pokemon`, {
2446
attack: $.field($.Output.Nullable($Scalar.Int)),
@@ -29,32 +51,45 @@ export const Pokemon = $.Object$(`Pokemon`, {
2951
name: $.field($.Output.Nullable($Scalar.String)),
3052
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
3153
trainer: $.field($.Output.Nullable(() => Trainer)),
54+
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
55+
type: $.field($.Output.Nullable(PokemonType)),
3256
})
3357

3458
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
3559
export const Trainer = $.Object$(`Trainer`, {
60+
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
61+
class: $.field($.Output.Nullable(TrainerClass)),
62+
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
63+
fans: $.field($.Output.Nullable($.Output.List(() => Patron))),
3664
id: $.field($.Output.Nullable($Scalar.Int)),
3765
name: $.field($.Output.Nullable($Scalar.String)),
3866
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
3967
pokemon: $.field($.Output.Nullable($.Output.List(() => Pokemon))),
4068
})
4169

70+
export const Being = $.Interface(`Being`, {
71+
id: $.field($.Output.Nullable($Scalar.Int)),
72+
name: $.field($.Output.Nullable($Scalar.String)),
73+
}, [Patron, Pokemon, Trainer])
4274
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
4375
export const Mutation = $.Object$(`Mutation`, {
4476
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
4577
addPokemon: $.field(
4678
$.Output.Nullable(() => Pokemon),
4779
$.Args({
48-
attack: $.Input.Field($Scalar.Int),
49-
defense: $.Input.Field($Scalar.Int),
50-
hp: $.Input.Field($Scalar.Int),
80+
attack: $.Input.Field($.Input.Nullable($Scalar.Int)),
81+
defense: $.Input.Field($.Input.Nullable($Scalar.Int)),
82+
hp: $.Input.Field($.Input.Nullable($Scalar.Int)),
5183
name: $.Input.Field($Scalar.String),
84+
type: $.Input.Field(PokemonType),
5285
}, false),
5386
),
5487
})
5588

5689
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
5790
export const Query = $.Object$(`Query`, {
91+
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
92+
beings: $.field($.Output.List(() => Being)),
5893
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
5994
pokemon: $.field($.Output.Nullable($.Output.List(() => Pokemon))),
6095
// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not.
@@ -84,15 +119,22 @@ export const $Index: Index = {
84119
allTypes: {
85120
Mutation,
86121
Query,
122+
Patron,
87123
Pokemon,
88124
Trainer,
125+
Being,
126+
PokemonType,
127+
TrainerClass,
89128
},
90129
objects: {
130+
Patron,
91131
Pokemon,
92132
Trainer,
93133
},
94134
unions: {},
95-
interfaces: {},
135+
interfaces: {
136+
Being,
137+
},
96138
error: {
97139
objects: {},
98140
objectsTypename: {},

examples/$/generated-clients/pokemon/modules/Select.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export namespace Select {
4444
export type Query<$SelectionSet extends SelectionSets.Query> = ResultSet.Root<$SelectionSet, Index, 'Query'>
4545
// Object Types
4646
// ------------
47+
export type Patron<$SelectionSet extends SelectionSets.Patron> = ResultSet.Object$<
48+
$SelectionSet,
49+
Index,
50+
Index['allTypes']['Patron']
51+
>
4752
export type Pokemon<$SelectionSet extends SelectionSets.Pokemon> = ResultSet.Object$<
4853
$SelectionSet,
4954
Index,
@@ -60,6 +65,9 @@ export namespace Select {
6065
// -- None --
6166
// Interface Types
6267
// ---------------
63-
64-
// -- None --
68+
export type Being<$SelectionSet extends SelectionSets.Being> = ResultSet.Interface<
69+
$SelectionSet,
70+
Index,
71+
Index['allTypes']['Being']
72+
>
6573
}

0 commit comments

Comments
 (0)