Skip to content

Commit

Permalink
fix ugh
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Apr 9, 2024
1 parent ecac369 commit 2fddd18
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 61 deletions.
8 changes: 4 additions & 4 deletions src/ResultSet/ResultSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type Subscription<$SelectionSetSubscription extends object, $Index extend
SimplifyDeep<Object<$SelectionSetSubscription, Exclude<$Index['Root']['Subscription'], null>, $Index>>

// dprint-ignore
export type Object<$SelectionSet, $Node extends Schema.Named.Object, $Index extends Schema.Index> =
export type Object<$SelectionSet, $Node extends Schema.Named.Obj, $Index extends Schema.Index> =
SelectionSet.IsSelectScalarsWildcard<$SelectionSet> extends true

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ type Interface<$SelectionSet, $Node extends Schema.Named.Interface, $Index exten
OnTypeFragment<$SelectionSet, $Node['implementors'][number], $Index>

// dprint-ignore
type OnTypeFragment<$SelectionSet, $Node extends Schema.Named.Object, $Index extends Schema.Index> =
type OnTypeFragment<$SelectionSet, $Node extends Schema.Named.Obj, $Index extends Schema.Index> =
$Node extends any // force distribution
? Object<
GetKeyOr<$SelectionSet, `on${Capitalize<$Node['fields']['__typename']['type']['type']>}`, {}> & SelectionSet.OmitOnTypeFragments<$SelectionSet>,
Expand Down Expand Up @@ -82,7 +82,7 @@ type FieldType<
$Type extends Schema.Field.Type.Output.List<infer $InnerType> ? Array<FieldType<$SelectionSet, $InnerType, $Index>> :
$Type extends Schema.Named.Enum<infer _, infer $Members> ? $Members[number] :
$Type extends Schema.Named.Scalar.Any ? ReturnType<$Type['codec']['decode']> :
$Type extends Schema.Named.Object ? Object<$SelectionSet,$Type,$Index> :
$Type extends Schema.Named.Obj ? Object<$SelectionSet,$Type,$Index> :
$Type extends Schema.Named.Interface ? Interface<$SelectionSet,$Type,$Index> :
$Type extends Schema.Named.Union ? Union<$SelectionSet,$Type,$Index> :
TSError<'FieldType', `Unknown type`, { $Type: $Type }>
Expand All @@ -104,5 +104,5 @@ type FieldDirectiveSkip<$SelectionSet> =

// dprint-ignore
export namespace Errors {
export type UnknownFieldName<$FieldName extends string, $Object extends Schema.Named.Object> = TSError<'Object', `field "${$FieldName}" does not exist on object "${$Object['fields']['__typename']['type']['type']}"`>
export type UnknownFieldName<$FieldName extends string, $Object extends Schema.Named.Obj> = TSError<'Object', `field "${$FieldName}" does not exist on object "${$Object['fields']['__typename']['type']['type']}"`>
}
10 changes: 5 additions & 5 deletions src/Schema/Index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable @typescript-eslint/ban-types */

import type { Object, Union } from './__.js'
import type { Obj, Union } from './__.js'

export interface Index {
Root: {
Query: null | Object
Mutation: null | Object
Subscription: null | Object
Query: null | Obj
Mutation: null | Obj
Subscription: null | Obj
}
objects: Record<string, Object>
objects: Record<string, Obj>
unions: Record<string, Union>
}
6 changes: 3 additions & 3 deletions src/Schema/NamedType/Interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/ban-types */

import type { Output } from '../__.js'
import type { Object } from './Object.js'
import type { Obj } from './Obj.js'

export type Interface<
$Name extends string = string,
$Fields extends Record<string, Output.Field<any>> = Record<string, Output.Field<any>>,
$Implementors extends [Object, ...Object[]] = [Object, ...Object[]],
$Implementors extends [Obj, ...Obj[]] = [Obj, ...Obj[]],
> = {
kind: 'Interface'
name: $Name
Expand All @@ -17,7 +17,7 @@ export type Interface<
export const Interface = <
$Name extends string,
$Fields extends Record<keyof $Fields, Output.Field>,
$Implementors extends [Object, ...Object[]],
$Implementors extends [Obj, ...Obj[]],
>(
name: $Name,
fields: $Fields,
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/NamedType/NamedType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { Digit, Letter } from '../../lib/prelude.js'
import type { Enum } from './Enum.js'
import type { InputObject } from './InputObjet.js'
import type { Interface } from './Interface.js'
import type { Object } from './Object.js'
import type { Obj } from './Obj.js'
import type { Scalar } from './Scalar/_.js'
import type { Union } from './Union.js'

export type AnyOutput = Interface | Enum | Object | Scalar.Any | Union
export type AnyOutput = Interface | Enum | Obj | Scalar.Any | Union
export type AnyInput = Enum | Scalar.Any | InputObject
export type Any = AnyOutput | AnyInput

Expand Down
12 changes: 6 additions & 6 deletions src/Schema/NamedType/Object.ts → src/Schema/NamedType/Obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Output } from '../Field/Type.js'
import type { Scalar } from './_.js'
import type { Enum } from './Enum.js'

export type Fields = Record<string, Output.Field<Output.List<any> | Output.Nullable<any> | Object | Enum | Scalar.Any>>
export type Fields = Record<string, Output.Field<Output.List<any> | Output.Nullable<any> | Obj | Enum | Scalar.Any>>

export type ObjectFields = {
__typename: Output.Field<Output.__typename>
} & Fields

export interface Object<
export interface Obj<
$Name extends string = string,
$Fields extends Fields = Fields,
> {
Expand All @@ -21,15 +21,15 @@ export interface Object<
}

// Naming this "Object" breaks Vitest: https://github.com/vitest-dev/vitest/issues/5463
const Object$ = <$Name extends string, $Fields extends Record<keyof $Fields, Output.Field>>(
export const Obj = <$Name extends string, $Fields extends Record<keyof $Fields, Output.Field>>(
name: $Name,
fields: $Fields,
): Object<$Name, $Fields> => ({
// eslint-disable-next-line
// @ts-ignore infinite depth issue
): Obj<$Name, $Fields> => ({
kind: `Object`,
fields: {
__typename: Output.field(Output.__typename(name)),
...fields,
},
})

export { Object$ as Object }
6 changes: 3 additions & 3 deletions src/Schema/NamedType/Union.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/ban-types */

import type { Object } from './Object.js'
import type { Obj } from './Obj.js'

export type Union<
$Name extends string = string,
$Members extends [Object, ...Object[]] = [Object, ...Object[]],
$Members extends [Obj, ...Obj[]] = [Obj, ...Obj[]],
> = {
kind: `Union`
name: $Name
Expand All @@ -13,7 +13,7 @@ export type Union<

export const Union = <
$Name extends string,
$Members extends [Object, ...Object[]],
$Members extends [Obj, ...Obj[]],
>(
name: $Name,
members: $Members,
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/NamedType/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export * from './Enum.js'
export * from './InputObjet.js'
export * from './Interface.js'
export * from './NamedType.js'
export * from './Object.js'
export * from './Obj.js'
export * from './Scalar/_.js'
export * from './Union.js'
26 changes: 13 additions & 13 deletions src/SelectionSet/SelectionSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import type { MaybeList, StringNonEmpty, Values } from '../lib/prelude.js'
import type { TSError } from '../lib/TSError.js'
import type { Schema } from '../Schema/__.js'

export type Query<$Index extends Schema.Index> = $Index['Root']['Query'] extends Schema.Named.Object
? Object<$Index['Root']['Query'], $Index>
export type Query<$Index extends Schema.Index> = $Index['Root']['Query'] extends Schema.Named.Obj
? Obj<$Index['Root']['Query'], $Index>
: never

export type Mutation<$Index extends Schema.Index> = $Index['Root']['Mutation'] extends Schema.Named.Object
? Object<$Index['Root']['Mutation'], $Index>
export type Mutation<$Index extends Schema.Index> = $Index['Root']['Mutation'] extends Schema.Named.Obj
? Obj<$Index['Root']['Mutation'], $Index>
: never

export type Subscription<$Index extends Schema.Index> = $Index['Root']['Subscription'] extends Schema.Named.Object
? Object<$Index['Root']['Subscription'], $Index>
export type Subscription<$Index extends Schema.Index> = $Index['Root']['Subscription'] extends Schema.Named.Obj
? Obj<$Index['Root']['Subscription'], $Index>
: never

// dprint-ignore
type Object<
$Fields extends Schema.Named.Object,
type Obj<
$Fields extends Schema.Named.Obj,
$Index extends Schema.Index,
> = Fields<$Fields['fields'], $Index>

Expand Down Expand Up @@ -73,7 +73,7 @@ export type Field<
// @ts-ignore infinite depth issue, can this be fixed?
$Field['typeUnwrapped']['kind'] extends 'Scalar' ? Indicator<$Field> :
$Field['typeUnwrapped']['kind'] extends 'Enum' ? Indicator<$Field> :
$Field['typeUnwrapped']['kind'] extends 'Object' ? Object<$Field['typeUnwrapped'], $Index> & FieldDirectives & Arguments<$Field> :
$Field['typeUnwrapped']['kind'] extends 'Object' ? Obj<$Field['typeUnwrapped'], $Index> & FieldDirectives & Arguments<$Field> :
$Field['typeUnwrapped']['kind'] extends 'Union' ? Union<$Field['typeUnwrapped'], $Index> :
$Field['typeUnwrapped']['kind'] extends 'Interface' ? Interface<$Field['typeUnwrapped'], $Index> :
TSError<'SelectionSetField', '$Field case not handled', { $Field: $Field }>
Expand All @@ -95,11 +95,11 @@ type Interface<$Node extends Schema.Named.Interface, $Index extends Schema.Index
>

// dprint-ignore
type InterfaceDistributed<$Node extends Schema.Named.Object, $Index extends Schema.Index> =
type InterfaceDistributed<$Node extends Schema.Named.Obj, $Index extends Schema.Index> =
$Node extends any
? {
[$typename in $Node['fields']['__typename']['type']['type'] as `on${Capitalize<$typename>}`]?:
Object<$Node, $Index> & FieldDirectives
Obj<$Node, $Index> & FieldDirectives
}
: never

Expand All @@ -109,11 +109,11 @@ type Union<$Node extends Schema.Named.Union, $Index extends Schema.Index> =
& { __typename?: NoArgsIndicator }

// dprint-ignore
type UnionDistributed<$Object extends Schema.Named.Object,$Index extends Schema.Index> =
type UnionDistributed<$Object extends Schema.Named.Obj, $Index extends Schema.Index> =
$Object extends any
? {
[$typename in $Object['fields']['__typename']['type']['type'] as `on${Capitalize<$typename>}`]?:
Object<$Object, $Index> & FieldDirectives
Obj<$Object, $Index> & FieldDirectives
}
: never

Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import request from './entrypoints/main.js'
import { type RootTypeName, standardScalarTypeNames } from './lib/graphql.js'
import type { Exact } from './lib/prelude.js'
import type { ResultSet } from './ResultSet/__.js'
import type { Object as ObjectType, Schema } from './Schema/__.js'
import type { Obj as ObjectType, Schema } from './Schema/__.js'
import { Output } from './Schema/__.js'
import type { Input } from './Schema/Field/Type.js'
import { readMaybeThunk } from './Schema/Field/Type.js'
Expand Down
22 changes: 11 additions & 11 deletions src/generator/__snapshots__/files.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -279,49 +279,49 @@ export const InputObject = _.InputObject(\`InputObject\`, {
dateRequired: _.Input.field($Scalar.Date),
})
export const DateObject1 = _.Object(\`DateObject1\`, {
export const DateObject1 = _.Obj(\`DateObject1\`, {
date1: _.Output.field(_.Output.Nullable($Scalar.Date)),
})
export const DateObject2 = _.Object(\`DateObject2\`, {
export const DateObject2 = _.Obj(\`DateObject2\`, {
date2: _.Output.field(_.Output.Nullable($Scalar.Date)),
})
export const Foo = _.Object(\`Foo\`, {
export const Foo = _.Obj(\`Foo\`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
})
export const Bar = _.Object(\`Bar\`, {
export const Bar = _.Obj(\`Bar\`, {
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
})
export const ObjectNested = _.Object(\`ObjectNested\`, {
export const ObjectNested = _.Obj(\`ObjectNested\`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
object: _.Output.field(_.Output.Nullable(() => Object1)),
})
export const lowerCaseObject = _.Object(\`lowerCaseObject\`, {
export const lowerCaseObject = _.Obj(\`lowerCaseObject\`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
})
export const lowerCaseObject2 = _.Object(\`lowerCaseObject2\`, {
export const lowerCaseObject2 = _.Obj(\`lowerCaseObject2\`, {
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
})
export const Object1 = _.Object(\`Object1\`, {
export const Object1 = _.Obj(\`Object1\`, {
string: _.Output.field(_.Output.Nullable($Scalar.String)),
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
float: _.Output.field(_.Output.Nullable($Scalar.Float)),
boolean: _.Output.field(_.Output.Nullable($Scalar.Boolean)),
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
})
export const Object1ImplementingInterface = _.Object(\`Object1ImplementingInterface\`, {
export const Object1ImplementingInterface = _.Obj(\`Object1ImplementingInterface\`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
})
export const Object2ImplementingInterface = _.Object(\`Object2ImplementingInterface\`, {
export const Object2ImplementingInterface = _.Obj(\`Object2ImplementingInterface\`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
boolean: _.Output.field(_.Output.Nullable($Scalar.Boolean)),
})
Expand All @@ -342,7 +342,7 @@ export const Interface = _.Interface(\`Interface\`, { id: _.Output.field(_.Outpu
Object2ImplementingInterface,
])
export const Query = _.Object(\`Query\`, {
export const Query = _.Obj(\`Query\`, {
date: _.Output.field(_.Output.Nullable($Scalar.Date)),
dateNonNull: _.Output.field($Scalar.Date),
dateList: _.Output.field(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Date)))),
Expand Down
2 changes: 1 addition & 1 deletion src/generator/code/schemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const object = (config: Config, type: GraphQLObjectType) => {
return `${field.name}: ${outputField(config, field)}`
}).join(`,\n`)
return `
export const ${type.name} = _.Object(\`${type.name}\`, {
export const ${type.name} = _.Obj(\`${type.name}\`, {
${fields}
})
`
Expand Down
22 changes: 11 additions & 11 deletions tests/ts/_/schema/generated/SchemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,49 @@ export const InputObject = _.InputObject(`InputObject`, {
dateRequired: _.Input.field($Scalar.Date),
})

export const DateObject1 = _.Object(`DateObject1`, {
export const DateObject1 = _.Obj(`DateObject1`, {
date1: _.Output.field(_.Output.Nullable($Scalar.Date)),
})

export const DateObject2 = _.Object(`DateObject2`, {
export const DateObject2 = _.Obj(`DateObject2`, {
date2: _.Output.field(_.Output.Nullable($Scalar.Date)),
})

export const Foo = _.Object(`Foo`, {
export const Foo = _.Obj(`Foo`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
})

export const Bar = _.Object(`Bar`, {
export const Bar = _.Obj(`Bar`, {
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
})

export const ObjectNested = _.Object(`ObjectNested`, {
export const ObjectNested = _.Obj(`ObjectNested`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
object: _.Output.field(_.Output.Nullable(() => Object1)),
})

export const lowerCaseObject = _.Object(`lowerCaseObject`, {
export const lowerCaseObject = _.Obj(`lowerCaseObject`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
})

export const lowerCaseObject2 = _.Object(`lowerCaseObject2`, {
export const lowerCaseObject2 = _.Obj(`lowerCaseObject2`, {
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
})

export const Object1 = _.Object(`Object1`, {
export const Object1 = _.Obj(`Object1`, {
string: _.Output.field(_.Output.Nullable($Scalar.String)),
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
float: _.Output.field(_.Output.Nullable($Scalar.Float)),
boolean: _.Output.field(_.Output.Nullable($Scalar.Boolean)),
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
})

export const Object1ImplementingInterface = _.Object(`Object1ImplementingInterface`, {
export const Object1ImplementingInterface = _.Obj(`Object1ImplementingInterface`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
int: _.Output.field(_.Output.Nullable($Scalar.Int)),
})

export const Object2ImplementingInterface = _.Object(`Object2ImplementingInterface`, {
export const Object2ImplementingInterface = _.Obj(`Object2ImplementingInterface`, {
id: _.Output.field(_.Output.Nullable($Scalar.ID)),
boolean: _.Output.field(_.Output.Nullable($Scalar.Boolean)),
})
Expand All @@ -73,7 +73,7 @@ export const Interface = _.Interface(`Interface`, { id: _.Output.field(_.Output.
Object2ImplementingInterface,
])

export const Query = _.Object(`Query`, {
export const Query = _.Obj(`Query`, {
date: _.Output.field(_.Output.Nullable($Scalar.Date)),
dateNonNull: _.Output.field($Scalar.Date),
dateList: _.Output.field(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Date)))),
Expand Down

0 comments on commit 2fddd18

Please sign in to comment.