Skip to content

Commit

Permalink
fix: enum decoding (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 27, 2024
1 parent 1bbc5dd commit baa7452
Show file tree
Hide file tree
Showing 53 changed files with 1,587 additions and 697 deletions.
8 changes: 8 additions & 0 deletions examples/$/generated-clients/pokemon/modules/MethodsRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export interface QueryMethods<$Config extends Utils.Config> {
'Query'
>
>
beings: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.beings>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Index,
'beings',
ResultSet.Field<$SelectionSet, Index['Root']['Query']['fields']['beings'], Index>
>
>
pokemon: <$SelectionSet>(selectionSet: Utils.Exact<$SelectionSet, SelectionSet.Query.pokemon>) => Promise<
Utils.ResolveOutputReturnRootField<
$Config,
Expand Down
26 changes: 26 additions & 0 deletions examples/$/generated-clients/pokemon/modules/MethodsSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import type * as $SelectionSets from './SelectionSets.js'
export interface $MethodsSelect {
Mutation: Mutation
Query: Query
Patron: Patron
Pokemon: Pokemon
Trainer: Trainer
Being: Being
}

//
Expand Down Expand Up @@ -64,10 +66,34 @@ export interface Query {
//
//

export interface Patron {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Patron>): $SelectionSet
}

export interface Pokemon {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Pokemon>): $SelectionSet
}

export interface Trainer {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Trainer>): $SelectionSet
}

//
//
//
//
//
//
// ==================================================================================================
// Interface
// ==================================================================================================
//
//
//
//
//
//

export interface Being {
<$SelectionSet>(selectionSet: $Utilities.Exact<$SelectionSet, $SelectionSets.Being>): $SelectionSet
}
43 changes: 38 additions & 5 deletions examples/$/generated-clients/pokemon/modules/SchemaBuildtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ export namespace Root {
addPokemon: $.Field<
$.Output.Nullable<Object.Pokemon>,
$.Args<{
attack: $.Input.Field<$Scalar.Int>
defense: $.Input.Field<$Scalar.Int>
hp: $.Input.Field<$Scalar.Int>
attack: $.Input.Field<$.Input.Nullable<$Scalar.Int>>
defense: $.Input.Field<$.Input.Nullable<$Scalar.Int>>
hp: $.Input.Field<$.Input.Nullable<$Scalar.Int>>
name: $.Input.Field<$Scalar.String>
type: $.Input.Field<Enum.PokemonType>
}, false>
>
}>

export type Query = $.Output.ObjectQuery<{
beings: $.Field<$.Output.List<Interface.Being>, null>
pokemon: $.Field<$.Output.Nullable<$.Output.List<Object.Pokemon>>, null>
pokemonByName: $.Field<
$.Output.Nullable<$.Output.List<Object.Pokemon>>,
Expand All @@ -44,7 +46,26 @@ export namespace Root {
// Enum //
// ------------------------------------------------------------ //
export namespace Enum {
// -- no types --
export type PokemonType = $.Enum<'PokemonType', ['electric', 'fire', 'grass', 'water']>

export type TrainerClass = $.Enum<
'TrainerClass',
[
'bugCatcher',
'camper',
'picnicker',
'psychic',
'psychicMedium',
'psychicYoungster',
'sailor',
'superNerd',
'tamer',
'teamRocketGrunt',
'triathlete',
'youngster',
'youth',
]
>
}
// ------------------------------------------------------------ //
// InputObject //
Expand All @@ -69,12 +90,21 @@ export namespace InputObject {
// Interface //
// ------------------------------------------------------------ //
export namespace Interface {
// -- no types --
export type Being = $.Interface<'Being', {
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
}, [Object.Patron, Object.Pokemon, Object.Trainer]>
}
// ------------------------------------------------------------ //
// Object //
// ------------------------------------------------------------ //
export namespace Object {
export type Patron = $.Object$2<'Patron', {
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
money: $.Field<$.Output.Nullable<$Scalar.Int>, null>
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
}>

export type Pokemon = $.Object$2<'Pokemon', {
attack: $.Field<$.Output.Nullable<$Scalar.Int>, null>
birthday: $.Field<$.Output.Nullable<$Scalar.Int>, null>
Expand All @@ -83,9 +113,12 @@ export namespace Object {
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
trainer: $.Field<$.Output.Nullable<Object.Trainer>, null>
type: $.Field<$.Output.Nullable<Enum.PokemonType>, null>
}>

export type Trainer = $.Object$2<'Trainer', {
class: $.Field<$.Output.Nullable<Enum.TrainerClass>, null>
fans: $.Field<$.Output.Nullable<$.Output.List<Object.Patron>>, null>
id: $.Field<$.Output.Nullable<$Scalar.Int>, null>
name: $.Field<$.Output.Nullable<$Scalar.String>, null>
pokemon: $.Field<$.Output.Nullable<$.Output.List<Object.Pokemon>>, null>
Expand Down
9 changes: 8 additions & 1 deletion examples/$/generated-clients/pokemon/modules/SchemaIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ export interface Index {
allTypes: {
Mutation: Schema.Root.Mutation
Query: Schema.Root.Query
PokemonType: Schema.Enum.PokemonType
TrainerClass: Schema.Enum.TrainerClass
Patron: Schema.Object.Patron
Pokemon: Schema.Object.Pokemon
Trainer: Schema.Object.Trainer
Being: Schema.Interface.Being
}
objects: {
Patron: Schema.Object.Patron
Pokemon: Schema.Object.Pokemon
Trainer: Schema.Object.Trainer
}
unions: {}
interfaces: {}
interfaces: {
Being: Schema.Interface.Being
}
error: {
objects: {}
objectsTypename: {}
Expand Down
52 changes: 47 additions & 5 deletions examples/$/generated-clients/pokemon/modules/SchemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ import * as Data from './Data.js'
import * as $Scalar from './Scalar.js'
import type { Index } from './SchemaIndex.js'
export const $defaultSchemaUrl = new URL('http://localhost:3000/graphql')

export const PokemonType = $.Enum(`PokemonType`, [`electric`, `fire`, `grass`, `water`])
export const TrainerClass = $.Enum(`TrainerClass`, [
`bugCatcher`,
`camper`,
`picnicker`,
`psychic`,
`psychicMedium`,
`psychicYoungster`,
`sailor`,
`superNerd`,
`tamer`,
`teamRocketGrunt`,
`triathlete`,
`youngster`,
`youth`,
])
export const DateFilter = $.InputObject(`DateFilter`, {
gte: $.Input.Field($.Input.Nullable($Scalar.Float)),
lte: $.Input.Field($.Input.Nullable($Scalar.Float)),
Expand All @@ -19,6 +34,13 @@ export const StringFilter = $.InputObject(`StringFilter`, {
contains: $.Input.Field($.Input.Nullable($Scalar.String)),
in: $.Input.Field($.Input.Nullable($.Input.List($Scalar.String))),
}, true)
// @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.
export const Patron = $.Object$(`Patron`, {
id: $.field($.Output.Nullable($Scalar.Int)),
money: $.field($.Output.Nullable($Scalar.Int)),
name: $.field($.Output.Nullable($Scalar.String)),
})

// @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.
export const Pokemon = $.Object$(`Pokemon`, {
attack: $.field($.Output.Nullable($Scalar.Int)),
Expand All @@ -29,32 +51,45 @@ export const Pokemon = $.Object$(`Pokemon`, {
name: $.field($.Output.Nullable($Scalar.String)),
// @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.
trainer: $.field($.Output.Nullable(() => Trainer)),
// @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.
type: $.field($.Output.Nullable(PokemonType)),
})

// @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.
export const Trainer = $.Object$(`Trainer`, {
// @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.
class: $.field($.Output.Nullable(TrainerClass)),
// @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.
fans: $.field($.Output.Nullable($.Output.List(() => Patron))),
id: $.field($.Output.Nullable($Scalar.Int)),
name: $.field($.Output.Nullable($Scalar.String)),
// @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.
pokemon: $.field($.Output.Nullable($.Output.List(() => Pokemon))),
})

export const Being = $.Interface(`Being`, {
id: $.field($.Output.Nullable($Scalar.Int)),
name: $.field($.Output.Nullable($Scalar.String)),
}, [Patron, Pokemon, Trainer])
// @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.
export const Mutation = $.Object$(`Mutation`, {
// @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.
addPokemon: $.field(
$.Output.Nullable(() => Pokemon),
$.Args({
attack: $.Input.Field($Scalar.Int),
defense: $.Input.Field($Scalar.Int),
hp: $.Input.Field($Scalar.Int),
attack: $.Input.Field($.Input.Nullable($Scalar.Int)),
defense: $.Input.Field($.Input.Nullable($Scalar.Int)),
hp: $.Input.Field($.Input.Nullable($Scalar.Int)),
name: $.Input.Field($Scalar.String),
type: $.Input.Field(PokemonType),
}, false),
),
})

// @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.
export const Query = $.Object$(`Query`, {
// @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.
beings: $.field($.Output.List(() => Being)),
// @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.
pokemon: $.field($.Output.Nullable($.Output.List(() => Pokemon))),
// @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.
Expand Down Expand Up @@ -84,15 +119,22 @@ export const $Index: Index = {
allTypes: {
Mutation,
Query,
Patron,
Pokemon,
Trainer,
Being,
PokemonType,
TrainerClass,
},
objects: {
Patron,
Pokemon,
Trainer,
},
unions: {},
interfaces: {},
interfaces: {
Being,
},
error: {
objects: {},
objectsTypename: {},
Expand Down
12 changes: 10 additions & 2 deletions examples/$/generated-clients/pokemon/modules/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export namespace Select {
export type Query<$SelectionSet extends SelectionSets.Query> = ResultSet.Root<$SelectionSet, Index, 'Query'>
// Object Types
// ------------
export type Patron<$SelectionSet extends SelectionSets.Patron> = ResultSet.Object$<
$SelectionSet,
Index,
Index['allTypes']['Patron']
>
export type Pokemon<$SelectionSet extends SelectionSets.Pokemon> = ResultSet.Object$<
$SelectionSet,
Index,
Expand All @@ -60,6 +65,9 @@ export namespace Select {
// -- None --
// Interface Types
// ---------------

// -- None --
export type Being<$SelectionSet extends SelectionSets.Being> = ResultSet.Interface<
$SelectionSet,
Index,
Index['allTypes']['Being']
>
}
Loading

0 comments on commit baa7452

Please sign in to comment.