diff --git a/src/ResultSet/ResultSet.ts b/src/ResultSet/ResultSet.ts index 23a290d76..2ba4e823c 100644 --- a/src/ResultSet/ResultSet.ts +++ b/src/ResultSet/ResultSet.ts @@ -3,7 +3,8 @@ import type { Simplify } from 'type-fest' import type { GetKeyOr, SimplifyDeep } from '../lib/prelude.js' import type { TSError } from '../lib/TSError.js' -import type { Schema } from '../Schema/__.js' +import type { Schema, SomeField } from '../Schema/__.js' +import type { PickScalarFields } from '../Schema/Output/Output.js' import type { SelectionSet } from '../SelectionSet/__.js' // dprint-ignore @@ -19,7 +20,7 @@ export type Subscription<$SelectionSetSubscription extends object, $Index extend SimplifyDeep, $Index>> // dprint-ignore -export type Object$<$SelectionSet, $Node extends Schema.Named.Object$2, $Index extends Schema.Index> = +export type Object$<$SelectionSet, $Node extends Schema.Output.Object$2, $Index extends Schema.Index> = SelectionSet.IsSelectScalarsWildcard<$SelectionSet> extends true /** @@ -27,10 +28,7 @@ export type Object$<$SelectionSet, $Node extends Schema.Named.Object$2, $Index e */ ? { - [$Key in keyof $Node['fields'] as $Node['fields'][$Key] extends Schema.Field.Field | {'typeUnwrapped':{kind:'Scalar'}} ? $Key : never]: - // eslint-disable-next-line - // @ts-ignore infinite depth issue, can this be fixed? - Field<$SelectionSet, Schema.Field.As<$Node['fields'][$Key]>, $Index> + [$Key in keyof PickScalarFields<$Node>]: Field<$SelectionSet, $Node['fields'][$Key], $Index> } /** * Handle fields in regular way. @@ -44,15 +42,15 @@ export type Object$<$SelectionSet, $Node extends Schema.Named.Object$2, $Index e }> // dprint-ignore -type Union<$SelectionSet, $Node extends Schema.Named.Union, $Index extends Schema.Index> = +type Union<$SelectionSet, $Node extends Schema.Output.Union, $Index extends Schema.Index> = OnTypeFragment<$SelectionSet,$Node['members'][number], $Index> // dprint-ignore -type Interface<$SelectionSet, $Node extends Schema.Named.Interface, $Index extends Schema.Index> = +type Interface<$SelectionSet, $Node extends Schema.Output.Interface, $Index extends Schema.Index> = OnTypeFragment<$SelectionSet, $Node['implementors'][number], $Index> // dprint-ignore -type OnTypeFragment<$SelectionSet, $Node extends Schema.Named.Object$2, $Index extends Schema.Index> = +type OnTypeFragment<$SelectionSet, $Node extends Schema.Output.Object$2, $Index extends Schema.Index> = $Node extends any // force distribution ? Object$< GetKeyOr<$SelectionSet, `on${Capitalize<$Node['fields']['__typename']['type']['type']>}`, {}> & SelectionSet.OmitOnTypeFragments<$SelectionSet>, @@ -62,7 +60,7 @@ type OnTypeFragment<$SelectionSet, $Node extends Schema.Named.Object$2, $Index e : never // dprint-ignore -type Field<$SelectionSet, $Field extends Schema.Field.Field, $Index extends Schema.Index> = +type Field<$SelectionSet, $Field extends SomeField, $Index extends Schema.Index> = $SelectionSet extends SelectionSet.Directive.Include.Negative | SelectionSet.Directive.Skip.Positive ? null : ( @@ -74,18 +72,18 @@ type Field<$SelectionSet, $Field extends Schema.Field.Field, $Index extends Sche // dprint-ignore type FieldType< $SelectionSet, - $Type extends Schema.Field.Type.Output.Any, + $Type extends Schema.Output.Any, $Index extends Schema.Index > =Simplify< - $Type extends Schema.Field.Type.Output.__typename ? $Value : - $Type extends Schema.Field.Type.Output.Nullable ? null | FieldType<$SelectionSet, $InnerType, $Index> : - $Type extends Schema.Field.Type.Output.List ? Array> : - $Type extends Schema.Named.Enum ? $Members[number] : - $Type extends Schema.Named.Scalar.Any ? ReturnType<$Type['codec']['decode']> : - $Type extends Schema.Named.Object$2 ? 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 }> + $Type extends Schema.__typename ? $Value : + $Type extends Schema.Output.Nullable ? null | FieldType<$SelectionSet, $InnerType, $Index> : + $Type extends Schema.Output.List ? Array> : + $Type extends Schema.Enum ? $Members[number] : + $Type extends Schema.Scalar.Any ? ReturnType<$Type['codec']['decode']> : + $Type extends Schema.Object$2 ? Object$<$SelectionSet,$Type,$Index> : + $Type extends Schema.Interface ? Interface<$SelectionSet,$Type,$Index> : + $Type extends Schema.Union ? Union<$SelectionSet,$Type,$Index> : + TSError<'FieldType', `Unknown type`, { $Type: $Type }> > // dprint-ignore @@ -104,5 +102,5 @@ type FieldDirectiveSkip<$SelectionSet> = // dprint-ignore export namespace Errors { - export type UnknownFieldName<$FieldName extends string, $Object extends Schema.Named.Object$2> = TSError<'Object', `field "${$FieldName}" does not exist on object "${$Object['fields']['__typename']['type']['type']}"`> + export type UnknownFieldName<$FieldName extends string, $Object extends Schema.Object$2> = TSError<'Object', `field "${$FieldName}" does not exist on object "${$Object['fields']['__typename']['type']['type']}"`> } diff --git a/src/Schema/Args.ts b/src/Schema/Args.ts new file mode 100644 index 000000000..37ff38842 --- /dev/null +++ b/src/Schema/Args.ts @@ -0,0 +1,26 @@ +import type { Input } from './_.js' +import type { Nullable } from './Input/types/Nullable.js' + +type InputFields = Record + +// dprint-ignore +export type InputFieldsAllNullable<$Fields extends InputFields> = + Exclude<$Fields[keyof $Fields], Nullable> extends never ? true : false + +export interface Args<$Fields extends InputFields> { + fields: $Fields +} + +export const Args = (fields: F): Args => { + return { + fields, + } +} + +export type OmitNullableFields<$Fields extends InputFields> = { + [Key in keyof $Fields as $Fields[Key] extends Input.Nullable ? never : Key]: $Fields[Key] +} + +export type PickNullableFields<$Fields extends InputFields> = { + [Key in keyof $Fields as $Fields[Key] extends Input.Nullable ? Key : never]: $Fields[Key] +} diff --git a/src/Schema/Field.ts b/src/Schema/Field.ts new file mode 100644 index 000000000..1a39f3208 --- /dev/null +++ b/src/Schema/Field.ts @@ -0,0 +1,31 @@ +import type { Args } from './Args.js' +import type { MaybeThunk } from './core/helpers.js' +import type { Hybrid } from './Hybrid/__.js' +import type { Output } from './Output/__.js' + +export type Field<$Type extends Output.Any, $Args extends Args | null> = { + type: $Type + args: $Args +} + +export const field = <$Type extends Output.Any, $Args extends null | Args = null>( + type: MaybeThunk<$Type>, + args: $Args = null as $Args, +): Field<$Type, $Args> => { + return { + // At type level "type" is not a thunk + type: type as any, // eslint-disable-line + args, + } +} + +// todo test non null union and non null interface fields +export type SomeField = Field< + Hybrid.Enum | Hybrid.Scalar.Any | Output.List | Output.Nullable | Output.Object$2, + Args | null +> + +export type SomeFields<$Keys extends string | number | symbol = string | number | symbol> = Record< + $Keys, + SomeField +> diff --git a/src/Schema/Field/Field.ts b/src/Schema/Field/Field.ts deleted file mode 100644 index 5414227d6..000000000 --- a/src/Schema/Field/Field.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { NamedType } from '../NamedType/__.js' -import type { Scalar } from '../NamedType/Scalar/_.js' - -import type * as Type from './Type.js' - -export type * as Type from './Type.js' - -export type As = T extends Field ? T : never - -export type Enum<$Args extends Args | null = null> = Field - -export type Scalar<$Args extends Args | null = Args | null> = Field - -export type String<$Args extends Args | null = null> = Field - -export type Number<$Args extends Args | null = null> = Field - -export type Boolean<$Args extends Args | null = null> = Field - -// export interface Args<$Fields extends Record = Record> { -export interface Args<$Fields extends any = any> { - allOptional: Exclude<$Fields[keyof $Fields], Type.Output.Nullable> extends never ? true : false - fields: $Fields -} - -export const Args = (fields: F): Args => { - return { - // @ts-expect-error todo................................... - allOptional: false, - fields, - } -} - -export type Field<$Type extends any = any, $Args extends Args | null = Args | null> = { - typeUnwrapped: Type.Output.Unwrap<$Type> - type: $Type - args: $Args -} diff --git a/src/Schema/Field/Type.ts b/src/Schema/Field/Type.ts deleted file mode 100644 index 96ca9b28f..000000000 --- a/src/Schema/Field/Type.ts +++ /dev/null @@ -1,133 +0,0 @@ -import type { TSError } from '../../lib/TSError.js' -import type { NamedType } from '../NamedType/__.js' -import type { Args } from './Field.js' - -const buildTimeOnly: any = undefined -export namespace Base { - export interface Nullable<$Type> { - kind: 'nullable' - type: $Type - } - export interface List<$Type> { - kind: 'list' - type: $Type - } -} - -export namespace Output { - export interface __typename<$Type extends string = string> { - kind: 'typename' - type: $Type - } - - export type Named = NamedType.AnyOutput - - export type Nullable<$Type extends Output.List | __typename | NamedType.AnyOutput> = Base.Nullable<$Type> - - export type List<$Type extends Any> = Base.List<$Type> - - export type Any = Output.List | __typename | Base.Nullable | NamedType.AnyOutput - - export const __typename = <$Type extends string>(type: $Type): __typename<$Type> => ({ kind: `typename`, type }) - - export const Nullable = <$Type extends __typename | List | NamedType.AnyOutput>( - type: MaybeThunk<$Type>, - ): Nullable<$Type> => ({ - kind: `nullable`, - // at type level "type" is not a thunk - type: type as any, // eslint-disable-line - }) - - export const List = <$Type extends Any>(type: $Type): List<$Type> => ({ - kind: `list`, - type, - }) - - // todo extends any because of infinite depth issue in generated schema types - // dprint-ignore - export type Unwrap<$Type extends any> = - $Type extends List ? Unwrap<$innerType> : - $Type extends Nullable ? Unwrap<$innerType> : - $Type extends __typename ? $Type['type'] : - $Type extends NamedType.AnyOutput ? $Type : - TSError<'Unwrap', 'Unknown $Type', { $Type: $Type }> - // dprint-ignore - export type UnwrapNonNull<$Type> = - $Type extends Nullable ? UnwrapNonNull<$innerType> - : $Type - - export const unwrapNonNull = <$Type extends Any>(type: $Type): UnwrapNonNull<$Type> => { - if (type.kind === `nullable`) return type.type - return type as UnwrapNonNull<$Type> - } - - export const unwrap = <$Type extends Any>(type: $Type): Unwrap<$Type> => { - // @ts-expect-error fixme - return type.kind === `named` ? type.type : unwrap(type.type) - } - - export const field = <$Type extends Any, $Args extends null | Args = null>( - type: MaybeThunk<$Type>, - args: $Args = null as $Args, - ): Field<$Type, $Args> => { - return { - typeUnwrapped: buildTimeOnly, // eslint-disable-line - // At type level "type" is not a thunk - type: type as any, // eslint-disable-line - args, - } - } - - export type Field<$Type extends any = any, $Args extends Args | null = Args | null> = { - typeUnwrapped: Unwrap<$Type> - type: $Type - args: $Args - } -} - -export namespace Input { - export type Nullable<$InnerType extends Any = Any> = Base.Nullable<$InnerType> - export type List<$InnerType extends Any = Any> = Base.List<$InnerType> - export type Any = List | Nullable | NamedType.AnyInput - - export const Nullable = <$InnerType extends Any>(type: MaybeThunk<$InnerType>): Nullable<$InnerType> => ({ - kind: `nullable`, - // at type level "type" is not a thunk - type: type as any, // eslint-disable-line - }) - - export const List = <$InnerType extends Any>(type: $InnerType): List<$InnerType> => ({ - kind: `list`, - type, - }) - - export const field = <$Type extends Any>(type: $Type): Field<$Type> => { - return { - type: type, - } - } - - // dprint-ignore - type UnwrapNonNull<$Type> = - $Type extends Nullable ? UnwrapNonNull<$innerType> - : $Type - - export const unwrapNullable = <$Type extends Any>(type: $Type): UnwrapNonNull<$Type> => { - if (type.kind === `nullable`) return type.type - // @ts-expect-error fixme - return type - } - - export type Field<$Type extends any = any> = { - // typeUnwrapped: Type.Output.Unwrap<$Type> - type: $Type - } -} - -type MaybeThunk<$Type> = $Type | Thunk<$Type> - -type Thunk<$Type> = () => $Type - -export const readMaybeThunk = (maybeThunk: MaybeThunk): T => - // @ts-expect-error fixme - typeof maybeThunk === `function` ? maybeThunk() : maybeThunk diff --git a/src/Schema/Field/_.ts b/src/Schema/Field/_.ts deleted file mode 100644 index f9956dd53..000000000 --- a/src/Schema/Field/_.ts +++ /dev/null @@ -1 +0,0 @@ -export * as Field from './__.js' diff --git a/src/Schema/Field/__.ts b/src/Schema/Field/__.ts deleted file mode 100644 index 3292e0087..000000000 --- a/src/Schema/Field/__.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Field.js' -export * from './Type.js' diff --git a/src/Schema/Hybrid/_.ts b/src/Schema/Hybrid/_.ts new file mode 100644 index 000000000..d2818dc2b --- /dev/null +++ b/src/Schema/Hybrid/_.ts @@ -0,0 +1,2 @@ +export * from './types/Enum.js' +export * from './types/Scalar/__.js' diff --git a/src/Schema/Hybrid/__.ts b/src/Schema/Hybrid/__.ts new file mode 100644 index 000000000..780cae1e4 --- /dev/null +++ b/src/Schema/Hybrid/__.ts @@ -0,0 +1 @@ +export * as Hybrid from './_.js' diff --git a/src/Schema/NamedType/Enum.ts b/src/Schema/Hybrid/types/Enum.ts similarity index 100% rename from src/Schema/NamedType/Enum.ts rename to src/Schema/Hybrid/types/Enum.ts diff --git a/src/Schema/NamedType/Scalar/Scalar.ts b/src/Schema/Hybrid/types/Scalar/Scalar.ts similarity index 100% rename from src/Schema/NamedType/Scalar/Scalar.ts rename to src/Schema/Hybrid/types/Scalar/Scalar.ts diff --git a/src/Schema/NamedType/Scalar/_.ts b/src/Schema/Hybrid/types/Scalar/__.ts similarity index 100% rename from src/Schema/NamedType/Scalar/_.ts rename to src/Schema/Hybrid/types/Scalar/__.ts diff --git a/src/Schema/NamedType/Scalar/codec.ts b/src/Schema/Hybrid/types/Scalar/codec.ts similarity index 100% rename from src/Schema/NamedType/Scalar/codec.ts rename to src/Schema/Hybrid/types/Scalar/codec.ts diff --git a/src/Schema/NamedType/Scalar/nativeScalarCodecs.ts b/src/Schema/Hybrid/types/Scalar/nativeScalarCodecs.ts similarity index 100% rename from src/Schema/NamedType/Scalar/nativeScalarCodecs.ts rename to src/Schema/Hybrid/types/Scalar/nativeScalarCodecs.ts diff --git a/src/Schema/Index.ts b/src/Schema/Index.ts deleted file mode 100644 index ef89e8be5..000000000 --- a/src/Schema/Index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { Object$2, Union } from './__.js' - -export interface Index { - Root: { - Query: null | Object$2 - Mutation: null | Object$2 - Subscription: null | Object$2 - } - objects: Record - unions: Record -} diff --git a/src/Schema/Input/Input.ts b/src/Schema/Input/Input.ts new file mode 100644 index 000000000..fb2765b10 --- /dev/null +++ b/src/Schema/Input/Input.ts @@ -0,0 +1,16 @@ +import type { Any } from './typeGroups.js' + +export * from './typeGroups.js' +export * from './types/InputObject.js' +export * from './types/List.js' +export * from './types/Nullable.js' + +export const field = <$Type extends Any>(type: $Type): Field<$Type> => { + return { + type: type, + } +} + +export type Field<$Type extends any = any> = { + type: $Type +} diff --git a/src/Schema/Input/__.ts b/src/Schema/Input/__.ts new file mode 100644 index 000000000..31e74e92c --- /dev/null +++ b/src/Schema/Input/__.ts @@ -0,0 +1 @@ +export * as Input from './Input.js' diff --git a/src/Schema/Input/typeGroups.ts b/src/Schema/Input/typeGroups.ts new file mode 100644 index 000000000..ce8aa897e --- /dev/null +++ b/src/Schema/Input/typeGroups.ts @@ -0,0 +1,8 @@ +import type { Hybrid } from '../Hybrid/__.js' +import type { InputObject } from './types/InputObject.js' +import type { List } from './types/List.js' +import type { Nullable } from './types/Nullable.js' + +export type Named = Hybrid.Enum | Hybrid.Scalar.Any | InputObject + +export type Any = List | Nullable | Named diff --git a/src/Schema/NamedType/InputObjet.ts b/src/Schema/Input/types/InputObject.ts similarity index 79% rename from src/Schema/NamedType/InputObjet.ts rename to src/Schema/Input/types/InputObject.ts index 416b016ae..c7db110ff 100644 --- a/src/Schema/NamedType/InputObjet.ts +++ b/src/Schema/Input/types/InputObject.ts @@ -1,8 +1,8 @@ -type Fields = Record +export type InputFields = Record export interface InputObject< $Name extends string = string, - $Fields extends Fields = Fields, + $Fields extends InputFields = InputFields, > { kind: 'InputObject' name: $Name diff --git a/src/Schema/Input/types/List.ts b/src/Schema/Input/types/List.ts new file mode 100644 index 000000000..8d70d4e34 --- /dev/null +++ b/src/Schema/Input/types/List.ts @@ -0,0 +1,9 @@ +import type { Base } from '../../core/helpers.js' +import type { Any } from '../typeGroups.js' + +export type List<$InnerType extends Any> = Base.List<$InnerType> + +export const List = <$InnerType extends Any>(type: $InnerType): List<$InnerType> => ({ + kind: `list`, + type, +}) diff --git a/src/Schema/Input/types/Nullable.ts b/src/Schema/Input/types/Nullable.ts new file mode 100644 index 000000000..89b296582 --- /dev/null +++ b/src/Schema/Input/types/Nullable.ts @@ -0,0 +1,24 @@ +import type { Base, MaybeThunk } from '../../core/helpers.js' +import type { Any, Named } from '../typeGroups.js' +import type { List } from './List.js' + +type InnerType = Named | List + +export type Nullable<$InnerType extends InnerType> = Base.Nullable<$InnerType> + +export const Nullable = <$InnerType extends InnerType>(type: MaybeThunk<$InnerType>): Nullable<$InnerType> => ({ + kind: `nullable`, + // at type level "type" is not a thunk + type: type as any, // eslint-disable-line +}) + +// dprint-ignore +type UnwrapNullable<$Type> = + $Type extends Nullable ? UnwrapNullable<$innerType> + : $Type + +export const unwrapNullable = <$Type extends Any>(type: $Type): UnwrapNullable<$Type> => { + if (type.kind === `nullable`) return type.type + // @ts-expect-error fixme + return type +} diff --git a/src/Schema/NamedType/Object.ts b/src/Schema/NamedType/Object.ts deleted file mode 100644 index 3ccec0ead..000000000 --- a/src/Schema/NamedType/Object.ts +++ /dev/null @@ -1,38 +0,0 @@ -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.Nullable | Object$2 | Enum | Scalar.Any> -> - -export type ObjectFields = { - __typename: Output.Field -} & Fields - -export interface Object$2< - $Name extends string = string, - $Fields extends Fields = Fields, -> { - kind: 'Object' - fields: { - __typename: Output.Field> - } & $Fields -} - -// Naming this "Object" breaks Vitest: https://github.com/vitest-dev/vitest/issues/5463 -export const Object$ = <$Name extends string, $Fields extends Record>( - name: $Name, - fields: $Fields, - // eslint-disable-next-line - // @ts-ignore infinite depth issue -): Object$2<$Name, $Fields> => ({ - kind: `Object`, - fields: { - __typename: Output.field(Output.__typename(name)), - ...fields, - }, -}) - -export { Object$ as Object } diff --git a/src/Schema/NamedType/_.ts b/src/Schema/NamedType/_.ts deleted file mode 100644 index 40e0b6247..000000000 --- a/src/Schema/NamedType/_.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './Enum.js' -export * from './InputObjet.js' -export * from './Interface.js' -export * from './NamedType.js' -export * from './Object.js' -export * from './Scalar/_.js' -export * from './Union.js' diff --git a/src/Schema/NamedType/__.ts b/src/Schema/NamedType/__.ts deleted file mode 100644 index 974d0f166..000000000 --- a/src/Schema/NamedType/__.ts +++ /dev/null @@ -1 +0,0 @@ -export * as NamedType from './_.js' diff --git a/src/Schema/Output/Output.ts b/src/Schema/Output/Output.ts new file mode 100644 index 000000000..8a91cf3ea --- /dev/null +++ b/src/Schema/Output/Output.ts @@ -0,0 +1,37 @@ +import type { TSError } from '../../lib/TSError.js' +import type { Any, Named } from './typeGroups.js' +import type { __typename } from './types/__typename.js' +import type { List } from './types/List.js' +import type { Nullable } from './types/Nullable.js' + +export * from './typeGroups.js' +export * from './types/__typename.js' +export * from './types/Interface.js' +export * from './types/List.js' +export * from './types/Nullable.js' +export * from './types/Object.js' +export * from './types/Union.js' + +// todo extends any because of infinite depth issue in generated schema types +// dprint-ignore +export type Unwrap<$Type extends any> = + $Type extends List ? Unwrap<$innerType> : + $Type extends Nullable ? Unwrap<$innerType> : + $Type extends __typename ? $Type['type'] : + $Type extends Named ? $Type : + TSError<'Unwrap', 'Unknown $Type', { $Type: $Type }> + +// dprint-ignore +export type UnwrapNullable<$Type> = + $Type extends Nullable ? UnwrapNullable<$innerType> + : $Type + +export const unwrapNullable = <$Type extends Any>(type: $Type): UnwrapNullable<$Type> => { + if (type.kind === `nullable`) return type.type + return type as UnwrapNullable<$Type> +} + +export const unwrap = <$Type extends Any>(type: $Type): Unwrap<$Type> => { + // @ts-expect-error fixme + return type.kind === `named` ? type.type : unwrap(type.type) +} diff --git a/src/Schema/Output/__.ts b/src/Schema/Output/__.ts new file mode 100644 index 000000000..6df548327 --- /dev/null +++ b/src/Schema/Output/__.ts @@ -0,0 +1 @@ +export * as Output from './Output.js' diff --git a/src/Schema/Output/typeGroups.ts b/src/Schema/Output/typeGroups.ts new file mode 100644 index 000000000..0531a5e05 --- /dev/null +++ b/src/Schema/Output/typeGroups.ts @@ -0,0 +1,20 @@ +import type { Hybrid } from '../Hybrid/__.js' +import type { Enum } from '../Hybrid/types/Enum.js' +import type { __typename } from './types/__typename.js' +import type { Interface } from './types/Interface.js' +import type { List } from './types/List.js' +import type { Nullable } from './types/Nullable.js' +import type { Object$2 } from './types/Object.js' +import type { Union } from './types/Union.js' + +export type Named = Interface | Enum | Object$2 | Union | Hybrid.Scalar.Any + +export type Unnamed = List | Nullable + +export type Any = Unnamed | Named | __typename + +// dprint-ignore +export type UnwrapToNamed<$Type extends Any> = + $Type extends List ? UnwrapToNamed<$Inner> : + $Type extends Nullable ? UnwrapToNamed<$Inner> : + $Type diff --git a/src/Schema/NamedType/Interface.ts b/src/Schema/Output/types/Interface.ts similarity index 76% rename from src/Schema/NamedType/Interface.ts rename to src/Schema/Output/types/Interface.ts index 492bb7a70..47c5c875c 100644 --- a/src/Schema/NamedType/Interface.ts +++ b/src/Schema/Output/types/Interface.ts @@ -1,9 +1,9 @@ -import type { Output } from '../__.js' +import type { SomeFields } from '../../Field.js' import type { Object$2 } from './Object.js' export type Interface< $Name extends string = string, - $Fields extends Record = Record, + $Fields extends SomeFields = SomeFields, $Implementors extends [Object$2, ...Object$2[]] = [Object$2, ...Object$2[]], > = { kind: 'Interface' @@ -14,7 +14,7 @@ export type Interface< export const Interface = < $Name extends string, - $Fields extends Record, + $Fields extends SomeFields, $Implementors extends [Object$2, ...Object$2[]], >( name: $Name, diff --git a/src/Schema/Output/types/List.ts b/src/Schema/Output/types/List.ts new file mode 100644 index 000000000..8606db9c1 --- /dev/null +++ b/src/Schema/Output/types/List.ts @@ -0,0 +1,12 @@ +import type { Base } from '../../core/helpers.js' +import type { Named } from '../typeGroups.js' +import type { Nullable } from './Nullable.js' + +type InnerType = Named | Nullable | List + +export type List<$Type extends InnerType> = Base.List<$Type> + +export const List = <$Type extends InnerType>(type: $Type): List<$Type> => ({ + kind: `list`, + type, +}) diff --git a/src/Schema/Output/types/Nullable.ts b/src/Schema/Output/types/Nullable.ts new file mode 100644 index 000000000..86815f8df --- /dev/null +++ b/src/Schema/Output/types/Nullable.ts @@ -0,0 +1,16 @@ +import type { Base, MaybeThunk } from '../../core/helpers.js' +import type { Named } from '../typeGroups.js' +import type { __typename } from './__typename.js' +import type { List } from './List.js' + +type InnerType = Named | List + +export type Nullable<$Type extends InnerType> = Base.Nullable<$Type> + +export const Nullable = <$Type extends InnerType>( + type: MaybeThunk<$Type>, +): Nullable<$Type> => ({ + kind: `nullable`, + // at type level "type" is not a thunk + type: type as any, // eslint-disable-line +}) diff --git a/src/Schema/Output/types/Object.ts b/src/Schema/Output/types/Object.ts new file mode 100644 index 000000000..3b21d8a9c --- /dev/null +++ b/src/Schema/Output/types/Object.ts @@ -0,0 +1,38 @@ +import type { Field, SomeFields } from '../../Field.js' +import { field } from '../../Field.js' +import type { Hybrid } from '../../Hybrid/__.js' +import type { UnwrapToNamed } from '../typeGroups.js' +import { __typename } from './__typename.js' + +export interface Object$2< + $Name extends string = string, + $Fields extends SomeFields = SomeFields, +> { + kind: 'Object' + fields: { + __typename: Field<__typename<$Name>, null> + } & $Fields +} + +// Naming this "Object" breaks Vitest: https://github.com/vitest-dev/vitest/issues/5463 +export const Object$ = <$Name extends string, $Fields extends Record>>( + name: $Name, + fields: $Fields, + // eslint-disable-next-line + // @ts-ignore infinite depth issue +): Object$2<$Name, $Fields> => ({ + kind: `Object`, + fields: { + __typename: field(__typename(name)), + ...fields, + }, +}) + +export { Object$ as Object } + +// dprint-ignore +export type PickScalarFields<$Object extends Object$2> = { + [ + $Key in keyof $Object['fields'] as UnwrapToNamed<$Object['fields'][$Key]['type']> extends Hybrid.Scalar.Any | __typename ? $Key : never + ]: $Object['fields'][$Key] +} diff --git a/src/Schema/NamedType/Union.ts b/src/Schema/Output/types/Union.ts similarity index 100% rename from src/Schema/NamedType/Union.ts rename to src/Schema/Output/types/Union.ts diff --git a/src/Schema/Output/types/__typename.ts b/src/Schema/Output/types/__typename.ts new file mode 100644 index 000000000..3a7dc3428 --- /dev/null +++ b/src/Schema/Output/types/__typename.ts @@ -0,0 +1,6 @@ +export interface __typename<$Type extends string = string> { + kind: 'typename' + type: $Type +} + +export const __typename = <$Type extends string>(type: $Type): __typename<$Type> => ({ kind: `typename`, type }) diff --git a/src/Schema/_.ts b/src/Schema/_.ts index d8ec79685..d8751cdd3 100644 --- a/src/Schema/_.ts +++ b/src/Schema/_.ts @@ -1,3 +1,13 @@ -export * from './Field/_.js' -export { Index } from './Index.js' -export * as Named from './NamedType/_.js' +export * from './Args.js' +export * from './core/Index.js' +export * from './core/Named/__.js' +export * from './Field.js' +export * from './Hybrid/types/Enum.js' +export * from './Hybrid/types/Scalar/__.js' +export * from './Input/__.js' +export * from './Input/types/InputObject.js' +export * from './Output/__.js' +export * from './Output/types/__typename.js' +export * from './Output/types/Interface.js' +export { Object$, Object$2 } from './Output/types/Object.js' +export * from './Output/types/Union.js' diff --git a/src/Schema/__.ts b/src/Schema/__.ts index a346e7390..ae38428c6 100644 --- a/src/Schema/__.ts +++ b/src/Schema/__.ts @@ -1,4 +1,2 @@ export * as Schema from './_.js' -export { Args, As, Field, Input, Output } from './Field/__.js' -export { Index } from './Index.js' -export * from './NamedType/_.js' +export * from './_.js' diff --git a/src/Schema/core/Index.ts b/src/Schema/core/Index.ts new file mode 100644 index 000000000..dc166a149 --- /dev/null +++ b/src/Schema/core/Index.ts @@ -0,0 +1,12 @@ +import type { Output } from '../Output/__.js' + +export interface Index { + Root: { + Query: null | Output.Object$2 + Mutation: null | Output.Object$2 + Subscription: null | Output.Object$2 + } + objects: Record + // todo unused? + unions: Record +} diff --git a/src/Schema/NamedType/NamedType.test-d.ts b/src/Schema/core/Named/NamedType.test-d.ts similarity index 100% rename from src/Schema/NamedType/NamedType.test-d.ts rename to src/Schema/core/Named/NamedType.test-d.ts diff --git a/src/Schema/NamedType/NamedType.ts b/src/Schema/core/Named/NamedType.ts similarity index 52% rename from src/Schema/NamedType/NamedType.ts rename to src/Schema/core/Named/NamedType.ts index f8337a736..09a761869 100644 --- a/src/Schema/NamedType/NamedType.ts +++ b/src/Schema/core/Named/NamedType.ts @@ -1,14 +1,4 @@ -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$2 } from './Object.js' -import type { Scalar } from './Scalar/_.js' -import type { Union } from './Union.js' - -export type AnyOutput = Interface | Enum | Object$2 | Scalar.Any | Union -export type AnyInput = Enum | Scalar.Any | InputObject -export type Any = AnyOutput | AnyInput +import type { Digit, Letter } from '../../../lib/prelude.js' /** * @see http://spec.graphql.org/draft/#sec-Names diff --git a/src/Schema/core/Named/_.ts b/src/Schema/core/Named/_.ts new file mode 100644 index 000000000..a5943c577 --- /dev/null +++ b/src/Schema/core/Named/_.ts @@ -0,0 +1 @@ +export * from './NamedType.js' diff --git a/src/Schema/core/Named/__.ts b/src/Schema/core/Named/__.ts new file mode 100644 index 000000000..07fafba48 --- /dev/null +++ b/src/Schema/core/Named/__.ts @@ -0,0 +1 @@ +export * as Named from './_.js' diff --git a/src/Schema/core/helpers.ts b/src/Schema/core/helpers.ts new file mode 100644 index 000000000..35680921e --- /dev/null +++ b/src/Schema/core/helpers.ts @@ -0,0 +1,18 @@ +export type MaybeThunk<$Type> = $Type | Thunk<$Type> + +export type Thunk<$Type> = () => $Type + +export const readMaybeThunk = (maybeThunk: MaybeThunk): T => + // @ts-expect-error fixme + typeof maybeThunk === `function` ? maybeThunk() : maybeThunk + +export namespace Base { + export interface Nullable<$Type> { + kind: 'nullable' + type: $Type + } + export interface List<$Type> { + kind: 'list' + type: $Type + } +} diff --git a/src/SelectionSet/SelectionSet.test-d.ts b/src/SelectionSet/SelectionSet.test-d.ts index 11168df24..34cd5118f 100644 --- a/src/SelectionSet/SelectionSet.test-d.ts +++ b/src/SelectionSet/SelectionSet.test-d.ts @@ -204,6 +204,7 @@ test(`Query`, () => { assertType({ stringWithArgInputObjectRequired: { $: { input: { idRequired: ``, dateRequired: new Date(0) } } } }) // @ts-expect-error missing "idRequired" field assertType({ stringWithArgInputObjectRequired: { $: { input: {} } } }) + // type x = Exclude['$']['input'] // all-optional + scalar + directive assertType({ stringWithArgs: { $: { boolean: true }, $skip: true } }) diff --git a/src/SelectionSet/SelectionSet.ts b/src/SelectionSet/SelectionSet.ts index 8e7cf20a4..d4ada60b4 100644 --- a/src/SelectionSet/SelectionSet.ts +++ b/src/SelectionSet/SelectionSet.ts @@ -2,37 +2,39 @@ 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$2 +import type { + InputFieldsAllNullable, + OmitNullableFields, + PickNullableFields, + Schema, + SomeField, + SomeFields, +} from '../Schema/__.js' + +export type Query<$Index extends Schema.Index> = $Index['Root']['Query'] extends Schema.Object$2 ? Object<$Index['Root']['Query'], $Index> : never -export type Mutation<$Index extends Schema.Index> = $Index['Root']['Mutation'] extends Schema.Named.Object$2 +export type Mutation<$Index extends Schema.Index> = $Index['Root']['Mutation'] extends Schema.Object$2 ? Object<$Index['Root']['Mutation'], $Index> : never -export type Subscription<$Index extends Schema.Index> = $Index['Root']['Subscription'] extends Schema.Named.Object$2 +export type Subscription<$Index extends Schema.Index> = $Index['Root']['Subscription'] extends Schema.Object$2 ? Object<$Index['Root']['Subscription'], $Index> : never // dprint-ignore -type Object< - $Fields extends Schema.Named.Object$2, - $Index extends Schema.Index, -> = Fields<$Fields['fields'], $Index> +type Object<$Object extends Schema.Object$2, $Index extends Schema.Index> = + Fields<$Object['fields'], $Index> // dprint-ignore -type Fields< - $Fields extends Schema.Named.Fields, - $Index extends Schema.Index, -> = +type Fields<$Fields extends SomeFields, $Index extends Schema.Index> = & { [Key in keyof $Fields]?: // eslint-disable-next-line // @ts-ignore excessive deep error, fixme? - Field, $Index> + Field<$Fields[Key], $Index> } & /** @@ -43,7 +45,7 @@ type Fields< [ Key in keyof $Fields as `${keyof $Fields & string}_as_${StringNonEmpty}` ]?: - Field, $Index> + Field<$Fields[Key], $Index> } & /** @@ -64,27 +66,31 @@ type Fields< export type IsSelectScalarsWildcard = SS extends { $scalars: ClientIndicatorPositive } ? true : false // dprint-ignore -export type Field< - $Field extends Schema.Field.Field, +export type Field<$Field extends SomeField, $Index extends Schema.Index> = Field_<$Field['type'], $Field, $Index> + +// dprint-ignore +export type Field_< + $type extends Schema.Output.Any, + $Field extends SomeField, $Index extends Schema.Index, > = - $Field['type']['kind'] extends 'typename' ? NoArgsIndicator : - // eslint-disable-next-line - // @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 'Union' ? Union<$Field['typeUnwrapped'], $Index> : - $Field['typeUnwrapped']['kind'] extends 'Interface' ? Interface<$Field['typeUnwrapped'], $Index> : - TSError<'SelectionSetField', '$Field case not handled', { $Field: $Field }> + $type extends Schema.Output.Nullable ? Field_<$typeInner, $Field, $Index> : + $type extends Schema.Output.List ? Field_<$typeInner, $Field, $Index> : + $type extends Schema.__typename ? NoArgsIndicator : + $type extends Schema.Scalar.Any ? Indicator<$Field> : + $type extends Schema.Enum ? Indicator<$Field> : + $type extends Schema.Object$2 ? Object<$type, $Index> & FieldDirectives & Arguments<$Field> : + $type extends Schema.Union ? Union<$type, $Index> : + $type extends Schema.Interface ? Interface<$type, $Index> : + TSError<'Field', '$Field case not handled', { $Field: $Field }> // dprint-ignore -type Arguments<$Field extends Schema.Field.Field> = -$Field['args'] extends Schema.Field.Args ? $Field['args']['allOptional'] extends true ? { $?: Args<$Field['args']> } : - { $: Args<$Field['args']> } : - {} +type Arguments<$Field extends SomeField> = + $Field['args'] extends Schema.Args ? InputFieldsAllNullable<$Field['args']['fields']> extends true ? { $?: Args<$Field['args']> } : + { $: Args<$Field['args']> } : + {} // dprint-ignore -type Interface<$Node extends Schema.Named.Interface, $Index extends Schema.Index> = +type Interface<$Node extends Schema.Interface, $Index extends Schema.Index> = & InterfaceDistributed<$Node['implementors'][number], $Index> & Fields< & $Node['fields'] @@ -95,7 +101,7 @@ type Interface<$Node extends Schema.Named.Interface, $Index extends Schema.Index > // dprint-ignore -type InterfaceDistributed<$Node extends Schema.Named.Object$2, $Index extends Schema.Index> = +type InterfaceDistributed<$Node extends Schema.Object$2, $Index extends Schema.Index> = $Node extends any ? { [$typename in $Node['fields']['__typename']['type']['type'] as `on${Capitalize<$typename>}`]?: @@ -104,12 +110,12 @@ type InterfaceDistributed<$Node extends Schema.Named.Object$2, $Index extends Sc : never // dprint-ignore -type Union<$Node extends Schema.Named.Union, $Index extends Schema.Index> = +type Union<$Node extends Schema.Union, $Index extends Schema.Index> = & UnionDistributed<$Node['members'][number], $Index> & { __typename?: NoArgsIndicator } // dprint-ignore -type UnionDistributed<$Object extends Schema.Named.Object$2,$Index extends Schema.Index> = +type UnionDistributed<$Object extends Schema.Object$2,$Index extends Schema.Index> = $Object extends any ? { [$typename in $Object['fields']['__typename']['type']['type'] as `on${Capitalize<$typename>}`]?: @@ -217,36 +223,32 @@ export type OmitNegativeIndicators<$SelectionSet> = { export type NoArgsIndicator = ClientIndicator | FieldDirectives // dprint-ignore -export type Indicator<$Field extends Schema.Field.Field = Schema.Field.Field> = -// $Field['args']['allOptional'] -$Field['args'] extends Schema.Field.Args ? $Field['args']['allOptional'] extends true - ? ({ $?: Args<$Field['args']> } & FieldDirectives) | ClientIndicator : - { $: Args<$Field['args']> } & FieldDirectives : - NoArgsIndicator +export type Indicator<$Field extends SomeField> = +$Field['args'] extends Schema.Args ? InputFieldsAllNullable<$Field['args']['fields']> extends true + ? ({ $?: Args<$Field['args']> } & FieldDirectives) | ClientIndicator : + { $: Args<$Field['args']> } & FieldDirectives : + NoArgsIndicator // dprint-ignore -export type Args<$Args extends Schema.Field.Args> = ArgFields<$Args['fields']> +export type Args<$Args extends Schema.Args> = ArgFields<$Args['fields']> -export type ArgFields<$ArgFields extends Schema.Named.InputObject['fields']> = +// dprint-ignore +export type ArgFields<$ArgFields extends Schema.InputObject['fields']> = & { - [ - Key in keyof $ArgFields as $ArgFields[Key] extends Schema.Field.Input.Nullable ? never : Key - ]: InferTypeInput<$ArgFields[Key]> - } + [Key in keyof OmitNullableFields<$ArgFields>]: InputField<$ArgFields[Key]> + } & { - [ - Key in keyof $ArgFields as $ArgFields[Key] extends Schema.Field.Input.Nullable ? Key : never - ]?: null | InferTypeInput<$ArgFields[Key]> - } + [Key in keyof PickNullableFields<$ArgFields>]?: InputField<$ArgFields[Key]> | null + } // dprint-ignore -type InferTypeInput<$InputType extends Schema.Field.Input.Any> = - $InputType extends Schema.Field.Input.Nullable ? InferTypeInput<$InnerType> | null : - $InputType extends Schema.Field.Input.List ? InferTypeInput<$InnerType>[] : - $InputType extends Schema.Named.InputObject ? ArgFields<$Fields> : - $InputType extends Schema.Named.Enum ? $Members[number] : - $InputType extends Schema.Named.Scalar.Any ? ReturnType<$InputType['codec']['decode']> : - TSError<'InferTypeInput', 'Unknown $InputType', { $InputType: $InputType }> // never +type InputField<$InputType extends Schema.Input.Any> = + $InputType extends Schema.Input.Nullable ? InputField<$InnerType> | null : + $InputType extends Schema.Input.List ? InputField<$InnerType>[] : + $InputType extends Schema.InputObject ? ArgFields<$Fields> : + $InputType extends Schema.Enum ? $Members[number] : + $InputType extends Schema.Scalar.Any ? ReturnType<$InputType['codec']['decode']> : + TSError<'InferTypeInput', 'Unknown $InputType', { $InputType: $InputType }> // never /** * @see https://spec.graphql.org/draft/#sec-Type-System.Directives.Built-in-Directives diff --git a/src/client.ts b/src/client.ts index 005dba7e0..93b87bca2 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5,8 +5,7 @@ import type { Exact } from './lib/prelude.js' import type { ResultSet } from './ResultSet/__.js' import type { Object$2, Schema } from './Schema/__.js' import { Output } from './Schema/__.js' -import type { Input } from './Schema/Field/Type.js' -import { readMaybeThunk } from './Schema/Field/Type.js' +import { readMaybeThunk } from './Schema/core/helpers.js' import { SelectionSet } from './SelectionSet/__.js' import type { Args } from './SelectionSet/SelectionSet.js' import type { GraphQLDocumentObject } from './SelectionSet/toGraphQLDocumentString.js' @@ -133,7 +132,7 @@ const encodeCustomScalarsArgs = (indexArgs: Args, valueArgs: SSValue.Args2) ) } -const encodeCustomScalarsArgValue = (indexArg: Input.Any, argValue: null | SSValue.Arg): any => { +const encodeCustomScalarsArgValue = (indexArg: Schema.Input.Any, argValue: null | SSValue.Arg): any => { if (argValue === null) return null // todo could check if index agrees is nullable. if (indexArg.kind === `nullable`) { return encodeCustomScalarsArgValue(indexArg.type, argValue) @@ -160,7 +159,7 @@ const decodeCustomScalars = (index: Object$2, documentQueryObject: object): obje if (!indexField) throw new Error(`Field not found: ${fieldName}`) const type = readMaybeThunk(indexField.type) - const typeWithoutNonNull = Output.unwrapNonNull(type) as Output.Named | Output.List + const typeWithoutNonNull = Output.unwrapNullable(type) as Output.Named | Output.List const v2 = decodeCustomScalarValue(typeWithoutNonNull, v) // eslint-disable-line return [fieldName, v2] }), @@ -175,10 +174,7 @@ const decodeCustomScalarValue = ( if (fieldValue === null) return null const indexTypeDethunked = readMaybeThunk(indexType) - const typeWithoutNonNull = Output.unwrapNonNull(indexTypeDethunked) as - | Output.Named - | Output.List - | Output.__typename + const typeWithoutNonNull = Output.unwrapNullable(indexTypeDethunked) as Exclude> if (typeWithoutNonNull.kind === `list`) { assertArray(fieldValue) diff --git a/src/entrypoints/alpha/scalars.ts b/src/entrypoints/alpha/scalars.ts index 554b6a894..c4eda2861 100644 --- a/src/entrypoints/alpha/scalars.ts +++ b/src/entrypoints/alpha/scalars.ts @@ -1 +1 @@ -export * from '../../Schema/NamedType/Scalar/Scalar.js' +export * from '../../Schema/Hybrid/types/Scalar/Scalar.js' diff --git a/src/generator/__snapshots__/files.test.ts.snap b/src/generator/__snapshots__/files.test.ts.snap index 8b5ae4edb..430d40a65 100644 --- a/src/generator/__snapshots__/files.test.ts.snap +++ b/src/generator/__snapshots__/files.test.ts.snap @@ -10,13 +10,13 @@ import type * as $Scalar from './Scalar.ts' export namespace Root { export type Query = $.Object$2<'Query', { - date: $.Field<$.Output.Nullable<$Scalar.Date>> - dateNonNull: $.Field<$Scalar.Date> - dateList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Date>>>> - dateObject1: $.Field<$.Output.Nullable> - dateUnion: $.Field<$.Output.Nullable> - dateInterface1: $.Field<$.Output.Nullable> - dateListNonNull: $.Field<$.Output.List<$Scalar.Date>> + date: $.Field<$.Output.Nullable<$Scalar.Date>, null> + dateNonNull: $.Field<$Scalar.Date, null> + dateList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Date>>>, null> + dateObject1: $.Field<$.Output.Nullable, null> + dateUnion: $.Field<$.Output.Nullable, null> + dateInterface1: $.Field<$.Output.Nullable, null> + dateListNonNull: $.Field<$.Output.List<$Scalar.Date>, null> dateArg: $.Field< $.Output.Nullable<$Scalar.Date>, $.Args<{ @@ -53,10 +53,10 @@ export namespace Root { input: $.Input.Nullable }> > - interface: $.Field<$.Output.Nullable> - id: $.Field<$.Output.Nullable<$Scalar.ID>> - idNonNull: $.Field<$Scalar.ID> - string: $.Field<$.Output.Nullable<$Scalar.String>> + interface: $.Field<$.Output.Nullable, null> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + idNonNull: $.Field<$Scalar.ID, null> + string: $.Field<$.Output.Nullable<$Scalar.String>, null> stringWithRequiredArg: $.Field< $.Output.Nullable<$Scalar.String>, $.Args<{ @@ -103,15 +103,16 @@ export namespace Root { input: InputObject.InputObject }> > - listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>> + listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>, null> listListInt: $.Field< - $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>> + $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>>, + null > - listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>> - listIntNonNull: $.Field<$.Output.List<$Scalar.Int>> - object: $.Field<$.Output.Nullable> - objectNonNull: $.Field - objectNested: $.Field<$.Output.Nullable> + listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>, null> + listIntNonNull: $.Field<$.Output.List<$Scalar.Int>, null> + object: $.Field<$.Output.Nullable, null> + objectNonNull: $.Field + objectNested: $.Field<$.Output.Nullable, null> objectWithArgs: $.Field< $.Output.Nullable, $.Args<{ @@ -122,12 +123,12 @@ export namespace Root { id: $.Input.Nullable<$Scalar.ID> }> > - fooBarUnion: $.Field<$.Output.Nullable> + fooBarUnion: $.Field<$.Output.Nullable, null> /** * Query enum field documentation. */ - abcEnum: $.Field<$.Output.Nullable> - lowerCaseUnion: $.Field<$.Output.Nullable> + abcEnum: $.Field<$.Output.Nullable, null> + lowerCaseUnion: $.Field<$.Output.Nullable, null> }> } @@ -166,11 +167,11 @@ export namespace InputObject { export namespace Interface { export type DateInterface1 = $.Interface<'DateInterface1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>> + date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> }, [Object.DateObject1]> export type Interface = $.Interface<'Interface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }, [Object.Object1ImplementingInterface, Object.Object2ImplementingInterface]> } @@ -180,11 +181,11 @@ export namespace Interface { export namespace Object { export type DateObject1 = $.Object$2<'DateObject1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>> + date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> }> export type DateObject2 = $.Object$2<'DateObject2', { - date2: $.Field<$.Output.Nullable<$Scalar.Date>> + date2: $.Field<$.Output.Nullable<$Scalar.Date>, null> }> /** @@ -196,42 +197,42 @@ export namespace Object { * * @deprecated Field a is deprecated. */ - id: $.Field<$.Output.Nullable<$Scalar.ID>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> export type Bar = $.Object$2<'Bar', { - int: $.Field<$.Output.Nullable<$Scalar.Int>> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> }> export type ObjectNested = $.Object$2<'ObjectNested', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> - object: $.Field<$.Output.Nullable> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + object: $.Field<$.Output.Nullable, null> }> export type lowerCaseObject = $.Object$2<'lowerCaseObject', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> export type lowerCaseObject2 = $.Object$2<'lowerCaseObject2', { - int: $.Field<$.Output.Nullable<$Scalar.Int>> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> }> export type Object1 = $.Object$2<'Object1', { - string: $.Field<$.Output.Nullable<$Scalar.String>> - int: $.Field<$.Output.Nullable<$Scalar.Int>> - float: $.Field<$.Output.Nullable<$Scalar.Float>> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>> - id: $.Field<$.Output.Nullable<$Scalar.ID>> + string: $.Field<$.Output.Nullable<$Scalar.String>, null> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> + float: $.Field<$.Output.Nullable<$Scalar.Float>, null> + boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> export type Object1ImplementingInterface = $.Object$2<'Object1ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> - int: $.Field<$.Output.Nullable<$Scalar.Int>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> }> export type Object2ImplementingInterface = $.Object$2<'Object2ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> }> } @@ -261,161 +262,156 @@ declare global { } } -export * from '../../../../../src/Schema/NamedType/Scalar/Scalar.js' +export * from '../../../../../src/Schema/Hybrid/types/Scalar/Scalar.js' export * from '../customScalarCodecs.js' " `; exports[`generates types from GraphQL SDL file 3`] = ` -"import * as _ from '../../../../../src/Schema/__.js' +"import * as $ from '../../../../../src/Schema/__.js' import * as $Scalar from './Scalar.js' -export const ABCEnum = _.Enum(\`ABCEnum\`, [\`A\`, \`B\`, \`C\`]) +export const ABCEnum = $.Enum(\`ABCEnum\`, [\`A\`, \`B\`, \`C\`]) -export const InputObject = _.InputObject(\`InputObject\`, { - id: _.Input.field(_.Input.Nullable($Scalar.ID)), - idRequired: _.Input.field($Scalar.ID), - date: _.Input.field(_.Input.Nullable($Scalar.Date)), - dateRequired: _.Input.field($Scalar.Date), +export const InputObject = $.InputObject(\`InputObject\`, { + id: $.Input.field($.Input.Nullable($Scalar.ID)), + idRequired: $.Input.field($Scalar.ID), + date: $.Input.field($.Input.Nullable($Scalar.Date)), + dateRequired: $.Input.field($Scalar.Date), }) -export const DateObject1 = _.Object$(\`DateObject1\`, { - date1: _.Output.field(_.Output.Nullable($Scalar.Date)), +export const DateObject1 = $.Object$(\`DateObject1\`, { + date1: $.field($.Output.Nullable($Scalar.Date)), }) -export const DateObject2 = _.Object$(\`DateObject2\`, { - date2: _.Output.field(_.Output.Nullable($Scalar.Date)), +export const DateObject2 = $.Object$(\`DateObject2\`, { + date2: $.field($.Output.Nullable($Scalar.Date)), }) -export const Foo = _.Object$(\`Foo\`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), +export const Foo = $.Object$(\`Foo\`, { + id: $.field($.Output.Nullable($Scalar.ID)), }) -export const Bar = _.Object$(\`Bar\`, { - int: _.Output.field(_.Output.Nullable($Scalar.Int)), +export const Bar = $.Object$(\`Bar\`, { + int: $.field($.Output.Nullable($Scalar.Int)), }) -export const ObjectNested = _.Object$(\`ObjectNested\`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - object: _.Output.field(_.Output.Nullable(() => Object1)), +export const ObjectNested = $.Object$(\`ObjectNested\`, { + id: $.field($.Output.Nullable($Scalar.ID)), + object: $.field($.Output.Nullable(() => Object1)), }) -export const lowerCaseObject = _.Object$(\`lowerCaseObject\`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), +export const lowerCaseObject = $.Object$(\`lowerCaseObject\`, { + id: $.field($.Output.Nullable($Scalar.ID)), }) -export const lowerCaseObject2 = _.Object$(\`lowerCaseObject2\`, { - int: _.Output.field(_.Output.Nullable($Scalar.Int)), +export const lowerCaseObject2 = $.Object$(\`lowerCaseObject2\`, { + int: $.field($.Output.Nullable($Scalar.Int)), }) -export const Object1 = _.Object$(\`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 Object1 = $.Object$(\`Object1\`, { + string: $.field($.Output.Nullable($Scalar.String)), + int: $.field($.Output.Nullable($Scalar.Int)), + float: $.field($.Output.Nullable($Scalar.Float)), + boolean: $.field($.Output.Nullable($Scalar.Boolean)), + id: $.field($.Output.Nullable($Scalar.ID)), }) -export const Object1ImplementingInterface = _.Object$(\`Object1ImplementingInterface\`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - int: _.Output.field(_.Output.Nullable($Scalar.Int)), +export const Object1ImplementingInterface = $.Object$(\`Object1ImplementingInterface\`, { + id: $.field($.Output.Nullable($Scalar.ID)), + int: $.field($.Output.Nullable($Scalar.Int)), }) -export const Object2ImplementingInterface = _.Object$(\`Object2ImplementingInterface\`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - boolean: _.Output.field(_.Output.Nullable($Scalar.Boolean)), +export const Object2ImplementingInterface = $.Object$(\`Object2ImplementingInterface\`, { + id: $.field($.Output.Nullable($Scalar.ID)), + boolean: $.field($.Output.Nullable($Scalar.Boolean)), }) -export const DateUnion = _.Union(\`DateUnion\`, [DateObject1, DateObject2]) +export const DateUnion = $.Union(\`DateUnion\`, [DateObject1, DateObject2]) -export const FooBarUnion = _.Union(\`FooBarUnion\`, [Foo, Bar]) +export const FooBarUnion = $.Union(\`FooBarUnion\`, [Foo, Bar]) -export const lowerCaseUnion = _.Union(\`lowerCaseUnion\`, [lowerCaseObject, lowerCaseObject2]) +export const lowerCaseUnion = $.Union(\`lowerCaseUnion\`, [lowerCaseObject, lowerCaseObject2]) -export const DateInterface1 = _.Interface( - \`DateInterface1\`, - { date1: _.Output.field(_.Output.Nullable($Scalar.Date)) }, - [DateObject1], -) -export const Interface = _.Interface(\`Interface\`, { id: _.Output.field(_.Output.Nullable($Scalar.ID)) }, [ +export const DateInterface1 = $.Interface(\`DateInterface1\`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [ + DateObject1, +]) +export const Interface = $.Interface(\`Interface\`, { id: $.field($.Output.Nullable($Scalar.ID)) }, [ Object1ImplementingInterface, Object2ImplementingInterface, ]) -export const Query = _.Object$(\`Query\`, { - date: _.Output.field(_.Output.Nullable($Scalar.Date)), - dateNonNull: _.Output.field($Scalar.Date), - dateList: _.Output.field(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Date)))), - dateObject1: _.Output.field(_.Output.Nullable(() => DateObject1)), - dateUnion: _.Output.field(_.Output.Nullable(() => DateUnion)), - dateInterface1: _.Output.field(_.Output.Nullable(() => DateInterface1)), - dateListNonNull: _.Output.field(_.Output.List($Scalar.Date)), - dateArg: _.Output.field(_.Output.Nullable($Scalar.Date), _.Args({ date: _.Input.Nullable($Scalar.Date) })), - dateArgNonNull: _.Output.field(_.Output.Nullable($Scalar.Date), _.Args({ date: $Scalar.Date })), - dateArgList: _.Output.field( - _.Output.Nullable($Scalar.Date), - _.Args({ date: _.Input.Nullable(_.Input.List(_.Input.Nullable($Scalar.Date))) }), - ), - dateArgNonNullList: _.Output.field( - _.Output.Nullable($Scalar.Date), - _.Args({ date: _.Input.List(_.Input.Nullable($Scalar.Date)) }), +export const Query = $.Object$(\`Query\`, { + date: $.field($.Output.Nullable($Scalar.Date)), + dateNonNull: $.field($Scalar.Date), + dateList: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Date)))), + dateObject1: $.field($.Output.Nullable(() => DateObject1)), + dateUnion: $.field($.Output.Nullable(() => DateUnion)), + dateInterface1: $.field($.Output.Nullable(() => DateInterface1)), + dateListNonNull: $.field($.Output.List($Scalar.Date)), + dateArg: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($Scalar.Date) })), + dateArgNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $Scalar.Date })), + dateArgList: $.field( + $.Output.Nullable($Scalar.Date), + $.Args({ date: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Date))) }), ), - dateArgNonNullListNonNull: _.Output.field( - _.Output.Nullable($Scalar.Date), - _.Args({ date: _.Input.List($Scalar.Date) }), + dateArgNonNullList: $.field( + $.Output.Nullable($Scalar.Date), + $.Args({ date: $.Input.List($.Input.Nullable($Scalar.Date)) }), ), - dateArgInputObject: _.Output.field(_.Output.Nullable($Scalar.Date), _.Args({ input: _.Input.Nullable(InputObject) })), - interface: _.Output.field(_.Output.Nullable(() => Interface)), - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - idNonNull: _.Output.field($Scalar.ID), - string: _.Output.field(_.Output.Nullable($Scalar.String)), - stringWithRequiredArg: _.Output.field(_.Output.Nullable($Scalar.String), _.Args({ string: $Scalar.String })), - stringWithArgs: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ - string: _.Input.Nullable($Scalar.String), - int: _.Input.Nullable($Scalar.Int), - float: _.Input.Nullable($Scalar.Float), - boolean: _.Input.Nullable($Scalar.Boolean), - id: _.Input.Nullable($Scalar.ID), + dateArgNonNullListNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.List($Scalar.Date) })), + dateArgInputObject: $.field($.Output.Nullable($Scalar.Date), $.Args({ input: $.Input.Nullable(InputObject) })), + interface: $.field($.Output.Nullable(() => Interface)), + id: $.field($.Output.Nullable($Scalar.ID)), + idNonNull: $.field($Scalar.ID), + string: $.field($.Output.Nullable($Scalar.String)), + stringWithRequiredArg: $.field($.Output.Nullable($Scalar.String), $.Args({ string: $Scalar.String })), + stringWithArgs: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ + string: $.Input.Nullable($Scalar.String), + int: $.Input.Nullable($Scalar.Int), + float: $.Input.Nullable($Scalar.Float), + boolean: $.Input.Nullable($Scalar.Boolean), + id: $.Input.Nullable($Scalar.ID), }), ), - stringWithArgEnum: _.Output.field(_.Output.Nullable($Scalar.String), _.Args({ ABCEnum: _.Input.Nullable(ABCEnum) })), - stringWithListArg: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ ints: _.Input.Nullable(_.Input.List(_.Input.Nullable($Scalar.Int))) }), + stringWithArgEnum: $.field($.Output.Nullable($Scalar.String), $.Args({ ABCEnum: $.Input.Nullable(ABCEnum) })), + stringWithListArg: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ ints: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Int))) }), ), - stringWithListArgRequired: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ ints: _.Input.List(_.Input.Nullable($Scalar.Int)) }), + stringWithListArgRequired: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ ints: $.Input.List($.Input.Nullable($Scalar.Int)) }), ), - stringWithArgInputObject: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ input: _.Input.Nullable(InputObject) }), + stringWithArgInputObject: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ input: $.Input.Nullable(InputObject) }), ), - stringWithArgInputObjectRequired: _.Output.field(_.Output.Nullable($Scalar.String), _.Args({ input: InputObject })), - listListIntNonNull: _.Output.field(_.Output.List(_.Output.List($Scalar.Int))), - listListInt: _.Output.field( - _.Output.Nullable(_.Output.List(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Int))))), + stringWithArgInputObjectRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ input: InputObject })), + listListIntNonNull: $.field($.Output.List($.Output.List($Scalar.Int))), + listListInt: $.field( + $.Output.Nullable($.Output.List($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int))))), ), - listInt: _.Output.field(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Int)))), - listIntNonNull: _.Output.field(_.Output.List($Scalar.Int)), - object: _.Output.field(_.Output.Nullable(() => Object1)), - objectNonNull: _.Output.field(() => Object1), - objectNested: _.Output.field(_.Output.Nullable(() => ObjectNested)), - objectWithArgs: _.Output.field( - _.Output.Nullable(() => Object1), - _.Args({ - string: _.Input.Nullable($Scalar.String), - int: _.Input.Nullable($Scalar.Int), - float: _.Input.Nullable($Scalar.Float), - boolean: _.Input.Nullable($Scalar.Boolean), - id: _.Input.Nullable($Scalar.ID), + listInt: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int)))), + listIntNonNull: $.field($.Output.List($Scalar.Int)), + object: $.field($.Output.Nullable(() => Object1)), + objectNonNull: $.field(() => Object1), + objectNested: $.field($.Output.Nullable(() => ObjectNested)), + objectWithArgs: $.field( + $.Output.Nullable(() => Object1), + $.Args({ + string: $.Input.Nullable($Scalar.String), + int: $.Input.Nullable($Scalar.Int), + float: $.Input.Nullable($Scalar.Float), + boolean: $.Input.Nullable($Scalar.Boolean), + id: $.Input.Nullable($Scalar.ID), }), ), - fooBarUnion: _.Output.field(_.Output.Nullable(() => FooBarUnion)), - abcEnum: _.Output.field(_.Output.Nullable(ABCEnum)), - lowerCaseUnion: _.Output.field(_.Output.Nullable(() => lowerCaseUnion)), + fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), + abcEnum: $.field($.Output.Nullable(ABCEnum)), + lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), }) export const $Index = { diff --git a/src/generator/code/schemaBuildtime.ts b/src/generator/code/schemaBuildtime.ts index a2d1e7ac3..60ec1c7f4 100644 --- a/src/generator/code/schemaBuildtime.ts +++ b/src/generator/code/schemaBuildtime.ts @@ -253,7 +253,7 @@ const renderOutputField = (config: Config, field: AnyField): string => { ? renderArgs(config, field.args) : null - return `$.Field<${type}${args ? `, ${args}` : ``}>` + return `$.Field<${type}${args ? `, ${args}` : `, null`}>` } const renderInputField = (config: Config, field: AnyField): string => { diff --git a/src/generator/code/schemaRuntime.ts b/src/generator/code/schemaRuntime.ts index 9dc92c873..1e4d364f5 100644 --- a/src/generator/code/schemaRuntime.ts +++ b/src/generator/code/schemaRuntime.ts @@ -29,7 +29,7 @@ export const generateRuntimeSchema = ( code.push( ` - import * as _ from '${config.libraryPaths.schema}' + import * as $ from '${config.libraryPaths.schema}' import * as $Scalar from './Scalar.js' `, ) @@ -60,10 +60,10 @@ const index = (config: Config) => { Subscription ${hasSubscription(config.typeMapByKind) ? `` : `:null`} }, objects: { - ${config.typeMapByKind.GraphQLObjectType.map(_ => _.name).join(`,\n`)}, + ${config.typeMapByKind.GraphQLObjectType.map(type => type.name).join(`,\n`)}, }, unions: { - ${config.typeMapByKind.GraphQLUnionType.map(_ => _.name).join(`,\n`)}, + ${config.typeMapByKind.GraphQLUnionType.map(type => type.name).join(`,\n`)}, } } ` @@ -72,7 +72,7 @@ const index = (config: Config) => { const union = (config: Config, type: GraphQLUnionType) => { // todo probably need thunks here const members = type.getTypes().map(t => t.name).join(`, `) - return `export const ${type.name} = _.Union(\`${type.name}\`, [${members}])\n` + return `export const ${type.name} = $.Union(\`${type.name}\`, [${members}])\n` } const interface$ = (config: Config, type: GraphQLInterfaceType) => { @@ -83,14 +83,14 @@ const interface$ = (config: Config, type: GraphQLInterfaceType) => { const fields = Object.values(type.getFields()).map((field) => { return `${field.name}: ${outputField(config, field)}` }).join(`,\n`) - return `export const ${type.name} = _.Interface(\`${type.name}\`, {${fields}}, [${implementors}])` + return `export const ${type.name} = $.Interface(\`${type.name}\`, {${fields}}, [${implementors}])` } const enum$ = (config: Config, type: GraphQLEnumType) => { const members = type.getValues().map((value) => { return `\`${value.name}\`` }).join(`, `) - return `export const ${type.name} = _.Enum(\`${type.name}\`, [${members}])` + return `export const ${type.name} = $.Enum(\`${type.name}\`, [${members}])` } const object = (config: Config, type: GraphQLObjectType) => { @@ -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} = $.Object$(\`${type.name}\`, { ${fields} }) ` @@ -109,7 +109,7 @@ const inputObject = (config: Config, type: GraphQLInputObjectType) => { `,\n`, ) return ` - export const ${type.name} = _.InputObject(\`${type.name}\`, { + export const ${type.name} = $.InputObject(\`${type.name}\`, { ${fields} }) ` @@ -117,18 +117,18 @@ const inputObject = (config: Config, type: GraphQLInputObjectType) => { const inputField = (config: Config, field: GraphQLInputField): string => { const type = buildType(`input`, config, field.type) - return `_.Input.field(${type})` + return `$.Input.field(${type})` } const outputField = (config: Config, field: AnyGraphQLOutputField): string => { const type = buildType(`output`, config, field.type) return field.args.length > 0 - ? `_.Output.field(${type}, ${renderArgs(config, field.args)})` - : `_.Output.field(${type})` + ? `$.field(${type}, ${renderArgs(config, field.args)})` + : `$.field(${type})` } const renderArgs = (config: Config, args: readonly GraphQLArgument[]) => { - return `_.Args({${args.map(arg => renderArg(config, arg)).join(`, `)}})` + return `$.Args({${args.map(arg => renderArg(config, arg)).join(`, `)}})` } const renderArg = (config: Config, arg: GraphQLArgument) => { @@ -161,14 +161,14 @@ const buildType = (direction: 'input' | 'output', config: Config, node: AnyClass const namedTypeReference = dispatchNamedType(config, nodeInner) const namedTypeCode = namedTypeReference return nullable - ? `_.${ns}.Nullable(${namedTypeCode})` + ? `$.${ns}.Nullable(${namedTypeCode})` : namedTypeCode } if (isListType(nodeInner)) { - const fieldType = `_.${ns}.List(${buildType(direction, config, nodeInner.ofType)})` as any as string + const fieldType = `$.${ns}.List(${buildType(direction, config, nodeInner.ofType)})` as any as string return nullable - ? `_.${ns}.Nullable(${fieldType})` + ? `$.${ns}.Nullable(${fieldType})` : fieldType } diff --git a/src/generator/files.test.ts b/src/generator/files.test.ts index 22d101a7e..7e81dfbfe 100644 --- a/src/generator/files.test.ts +++ b/src/generator/files.test.ts @@ -9,7 +9,7 @@ test(`generates types from GraphQL SDL file`, async () => { code: { libraryPaths: { schema: `../../../../../src/Schema/__.js`, - scalars: `../../../../../src/Schema/NamedType/Scalar/Scalar.js`, + scalars: `../../../../../src/Schema/Hybrid/types/Scalar/Scalar.js`, }, }, }) diff --git a/src/generator/files.ts b/src/generator/files.ts index 1c33a13fd..e5bf2d063 100644 --- a/src/generator/files.ts +++ b/src/generator/files.ts @@ -26,7 +26,7 @@ export const generateFiles = async (input: Input) => { customScalarCodecsFilePath.replace(/\.ts$/, `.js`), ) const customScalarCodecsPathExists = await fileExists(customScalarCodecsFilePath) - const formatter = (input.format ?? true) ? createFromBuffer(await fs.readFile(getPath())) : undefined + const typeScriptFormatter = (input.format ?? true) ? createFromBuffer(await fs.readFile(getPath())) : undefined const code = generateCode({ schemaSource, @@ -35,7 +35,7 @@ export const generateFiles = async (input: Input) => { }, ...input.code, options: { - formatter, + formatter: typeScriptFormatter, customScalars: customScalarCodecsPathExists, }, }) diff --git a/src/lib/prelude.ts b/src/lib/prelude.ts index c9a92ed0f..cd1a05bfd 100644 --- a/src/lib/prelude.ts +++ b/src/lib/prelude.ts @@ -186,3 +186,5 @@ export const fileExists = async (path: string) => { }), ) } + +export type As = U extends T ? U : never diff --git a/tests/ts/_/schema/customScalarCodecs.ts b/tests/ts/_/schema/customScalarCodecs.ts index 037fc63eb..cda91956c 100644 --- a/tests/ts/_/schema/customScalarCodecs.ts +++ b/tests/ts/_/schema/customScalarCodecs.ts @@ -1,5 +1,5 @@ import { Scalar } from '../../../../src/Schema/__.js' -import type { Codec } from '../../../../src/Schema/NamedType/Scalar/codec.js' +import type { Codec } from '../../../../src/Schema/Hybrid/types/Scalar/codec.js' export const Date = Scalar.scalar<'Date', Codec>(`Date`, { encode: value => value.getTime(), diff --git a/tests/ts/_/schema/generated/Scalar.ts b/tests/ts/_/schema/generated/Scalar.ts index 77463f759..e0ae1e408 100644 --- a/tests/ts/_/schema/generated/Scalar.ts +++ b/tests/ts/_/schema/generated/Scalar.ts @@ -6,5 +6,5 @@ declare global { } } -export * from '../../../../../src/Schema/NamedType/Scalar/Scalar.js' +export * from '../../../../../src/Schema/Hybrid/types/Scalar/Scalar.js' export * from '../customScalarCodecs.js' diff --git a/tests/ts/_/schema/generated/SchemaBuildtime.ts b/tests/ts/_/schema/generated/SchemaBuildtime.ts index c45b2d9ff..7e635b216 100644 --- a/tests/ts/_/schema/generated/SchemaBuildtime.ts +++ b/tests/ts/_/schema/generated/SchemaBuildtime.ts @@ -7,13 +7,13 @@ import type * as $Scalar from './Scalar.ts' export namespace Root { export type Query = $.Object$2<'Query', { - date: $.Field<$.Output.Nullable<$Scalar.Date>> - dateNonNull: $.Field<$Scalar.Date> - dateList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Date>>>> - dateObject1: $.Field<$.Output.Nullable> - dateUnion: $.Field<$.Output.Nullable> - dateInterface1: $.Field<$.Output.Nullable> - dateListNonNull: $.Field<$.Output.List<$Scalar.Date>> + date: $.Field<$.Output.Nullable<$Scalar.Date>, null> + dateNonNull: $.Field<$Scalar.Date, null> + dateList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Date>>>, null> + dateObject1: $.Field<$.Output.Nullable, null> + dateUnion: $.Field<$.Output.Nullable, null> + dateInterface1: $.Field<$.Output.Nullable, null> + dateListNonNull: $.Field<$.Output.List<$Scalar.Date>, null> dateArg: $.Field< $.Output.Nullable<$Scalar.Date>, $.Args<{ @@ -50,10 +50,10 @@ export namespace Root { input: $.Input.Nullable }> > - interface: $.Field<$.Output.Nullable> - id: $.Field<$.Output.Nullable<$Scalar.ID>> - idNonNull: $.Field<$Scalar.ID> - string: $.Field<$.Output.Nullable<$Scalar.String>> + interface: $.Field<$.Output.Nullable, null> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + idNonNull: $.Field<$Scalar.ID, null> + string: $.Field<$.Output.Nullable<$Scalar.String>, null> stringWithRequiredArg: $.Field< $.Output.Nullable<$Scalar.String>, $.Args<{ @@ -100,15 +100,16 @@ export namespace Root { input: InputObject.InputObject }> > - listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>> + listListIntNonNull: $.Field<$.Output.List<$.Output.List<$Scalar.Int>>, null> listListInt: $.Field< - $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>> + $.Output.Nullable<$.Output.List<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>>>, + null > - listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>> - listIntNonNull: $.Field<$.Output.List<$Scalar.Int>> - object: $.Field<$.Output.Nullable> - objectNonNull: $.Field - objectNested: $.Field<$.Output.Nullable> + listInt: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable<$Scalar.Int>>>, null> + listIntNonNull: $.Field<$.Output.List<$Scalar.Int>, null> + object: $.Field<$.Output.Nullable, null> + objectNonNull: $.Field + objectNested: $.Field<$.Output.Nullable, null> objectWithArgs: $.Field< $.Output.Nullable, $.Args<{ @@ -119,12 +120,12 @@ export namespace Root { id: $.Input.Nullable<$Scalar.ID> }> > - fooBarUnion: $.Field<$.Output.Nullable> + fooBarUnion: $.Field<$.Output.Nullable, null> /** * Query enum field documentation. */ - abcEnum: $.Field<$.Output.Nullable> - lowerCaseUnion: $.Field<$.Output.Nullable> + abcEnum: $.Field<$.Output.Nullable, null> + lowerCaseUnion: $.Field<$.Output.Nullable, null> }> } @@ -163,11 +164,11 @@ export namespace InputObject { export namespace Interface { export type DateInterface1 = $.Interface<'DateInterface1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>> + date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> }, [Object.DateObject1]> export type Interface = $.Interface<'Interface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }, [Object.Object1ImplementingInterface, Object.Object2ImplementingInterface]> } @@ -177,11 +178,11 @@ export namespace Interface { export namespace Object { export type DateObject1 = $.Object$2<'DateObject1', { - date1: $.Field<$.Output.Nullable<$Scalar.Date>> + date1: $.Field<$.Output.Nullable<$Scalar.Date>, null> }> export type DateObject2 = $.Object$2<'DateObject2', { - date2: $.Field<$.Output.Nullable<$Scalar.Date>> + date2: $.Field<$.Output.Nullable<$Scalar.Date>, null> }> /** @@ -193,42 +194,42 @@ export namespace Object { * * @deprecated Field a is deprecated. */ - id: $.Field<$.Output.Nullable<$Scalar.ID>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> export type Bar = $.Object$2<'Bar', { - int: $.Field<$.Output.Nullable<$Scalar.Int>> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> }> export type ObjectNested = $.Object$2<'ObjectNested', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> - object: $.Field<$.Output.Nullable> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + object: $.Field<$.Output.Nullable, null> }> export type lowerCaseObject = $.Object$2<'lowerCaseObject', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> export type lowerCaseObject2 = $.Object$2<'lowerCaseObject2', { - int: $.Field<$.Output.Nullable<$Scalar.Int>> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> }> export type Object1 = $.Object$2<'Object1', { - string: $.Field<$.Output.Nullable<$Scalar.String>> - int: $.Field<$.Output.Nullable<$Scalar.Int>> - float: $.Field<$.Output.Nullable<$Scalar.Float>> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>> - id: $.Field<$.Output.Nullable<$Scalar.ID>> + string: $.Field<$.Output.Nullable<$Scalar.String>, null> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> + float: $.Field<$.Output.Nullable<$Scalar.Float>, null> + boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> }> export type Object1ImplementingInterface = $.Object$2<'Object1ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> - int: $.Field<$.Output.Nullable<$Scalar.Int>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + int: $.Field<$.Output.Nullable<$Scalar.Int>, null> }> export type Object2ImplementingInterface = $.Object$2<'Object2ImplementingInterface', { - id: $.Field<$.Output.Nullable<$Scalar.ID>> - boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>> + id: $.Field<$.Output.Nullable<$Scalar.ID>, null> + boolean: $.Field<$.Output.Nullable<$Scalar.Boolean>, null> }> } diff --git a/tests/ts/_/schema/generated/SchemaRuntime.ts b/tests/ts/_/schema/generated/SchemaRuntime.ts index 5d1a6e914..25a605712 100644 --- a/tests/ts/_/schema/generated/SchemaRuntime.ts +++ b/tests/ts/_/schema/generated/SchemaRuntime.ts @@ -1,152 +1,147 @@ -import * as _ from '../../../../../src/Schema/__.js' +import * as $ from '../../../../../src/Schema/__.js' import * as $Scalar from './Scalar.js' -export const ABCEnum = _.Enum(`ABCEnum`, [`A`, `B`, `C`]) +export const ABCEnum = $.Enum(`ABCEnum`, [`A`, `B`, `C`]) -export const InputObject = _.InputObject(`InputObject`, { - id: _.Input.field(_.Input.Nullable($Scalar.ID)), - idRequired: _.Input.field($Scalar.ID), - date: _.Input.field(_.Input.Nullable($Scalar.Date)), - dateRequired: _.Input.field($Scalar.Date), +export const InputObject = $.InputObject(`InputObject`, { + id: $.Input.field($.Input.Nullable($Scalar.ID)), + idRequired: $.Input.field($Scalar.ID), + date: $.Input.field($.Input.Nullable($Scalar.Date)), + dateRequired: $.Input.field($Scalar.Date), }) -export const DateObject1 = _.Object$(`DateObject1`, { - date1: _.Output.field(_.Output.Nullable($Scalar.Date)), +export const DateObject1 = $.Object$(`DateObject1`, { + date1: $.field($.Output.Nullable($Scalar.Date)), }) -export const DateObject2 = _.Object$(`DateObject2`, { - date2: _.Output.field(_.Output.Nullable($Scalar.Date)), +export const DateObject2 = $.Object$(`DateObject2`, { + date2: $.field($.Output.Nullable($Scalar.Date)), }) -export const Foo = _.Object$(`Foo`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), +export const Foo = $.Object$(`Foo`, { + id: $.field($.Output.Nullable($Scalar.ID)), }) -export const Bar = _.Object$(`Bar`, { - int: _.Output.field(_.Output.Nullable($Scalar.Int)), +export const Bar = $.Object$(`Bar`, { + int: $.field($.Output.Nullable($Scalar.Int)), }) -export const ObjectNested = _.Object$(`ObjectNested`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - object: _.Output.field(_.Output.Nullable(() => Object1)), +export const ObjectNested = $.Object$(`ObjectNested`, { + id: $.field($.Output.Nullable($Scalar.ID)), + object: $.field($.Output.Nullable(() => Object1)), }) -export const lowerCaseObject = _.Object$(`lowerCaseObject`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), +export const lowerCaseObject = $.Object$(`lowerCaseObject`, { + id: $.field($.Output.Nullable($Scalar.ID)), }) -export const lowerCaseObject2 = _.Object$(`lowerCaseObject2`, { - int: _.Output.field(_.Output.Nullable($Scalar.Int)), +export const lowerCaseObject2 = $.Object$(`lowerCaseObject2`, { + int: $.field($.Output.Nullable($Scalar.Int)), }) -export const Object1 = _.Object$(`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 Object1 = $.Object$(`Object1`, { + string: $.field($.Output.Nullable($Scalar.String)), + int: $.field($.Output.Nullable($Scalar.Int)), + float: $.field($.Output.Nullable($Scalar.Float)), + boolean: $.field($.Output.Nullable($Scalar.Boolean)), + id: $.field($.Output.Nullable($Scalar.ID)), }) -export const Object1ImplementingInterface = _.Object$(`Object1ImplementingInterface`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - int: _.Output.field(_.Output.Nullable($Scalar.Int)), +export const Object1ImplementingInterface = $.Object$(`Object1ImplementingInterface`, { + id: $.field($.Output.Nullable($Scalar.ID)), + int: $.field($.Output.Nullable($Scalar.Int)), }) -export const Object2ImplementingInterface = _.Object$(`Object2ImplementingInterface`, { - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - boolean: _.Output.field(_.Output.Nullable($Scalar.Boolean)), +export const Object2ImplementingInterface = $.Object$(`Object2ImplementingInterface`, { + id: $.field($.Output.Nullable($Scalar.ID)), + boolean: $.field($.Output.Nullable($Scalar.Boolean)), }) -export const DateUnion = _.Union(`DateUnion`, [DateObject1, DateObject2]) +export const DateUnion = $.Union(`DateUnion`, [DateObject1, DateObject2]) -export const FooBarUnion = _.Union(`FooBarUnion`, [Foo, Bar]) +export const FooBarUnion = $.Union(`FooBarUnion`, [Foo, Bar]) -export const lowerCaseUnion = _.Union(`lowerCaseUnion`, [lowerCaseObject, lowerCaseObject2]) +export const lowerCaseUnion = $.Union(`lowerCaseUnion`, [lowerCaseObject, lowerCaseObject2]) -export const DateInterface1 = _.Interface( - `DateInterface1`, - { date1: _.Output.field(_.Output.Nullable($Scalar.Date)) }, - [DateObject1], -) -export const Interface = _.Interface(`Interface`, { id: _.Output.field(_.Output.Nullable($Scalar.ID)) }, [ +export const DateInterface1 = $.Interface(`DateInterface1`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [ + DateObject1, +]) +export const Interface = $.Interface(`Interface`, { id: $.field($.Output.Nullable($Scalar.ID)) }, [ Object1ImplementingInterface, Object2ImplementingInterface, ]) -export const Query = _.Object$(`Query`, { - date: _.Output.field(_.Output.Nullable($Scalar.Date)), - dateNonNull: _.Output.field($Scalar.Date), - dateList: _.Output.field(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Date)))), - dateObject1: _.Output.field(_.Output.Nullable(() => DateObject1)), - dateUnion: _.Output.field(_.Output.Nullable(() => DateUnion)), - dateInterface1: _.Output.field(_.Output.Nullable(() => DateInterface1)), - dateListNonNull: _.Output.field(_.Output.List($Scalar.Date)), - dateArg: _.Output.field(_.Output.Nullable($Scalar.Date), _.Args({ date: _.Input.Nullable($Scalar.Date) })), - dateArgNonNull: _.Output.field(_.Output.Nullable($Scalar.Date), _.Args({ date: $Scalar.Date })), - dateArgList: _.Output.field( - _.Output.Nullable($Scalar.Date), - _.Args({ date: _.Input.Nullable(_.Input.List(_.Input.Nullable($Scalar.Date))) }), - ), - dateArgNonNullList: _.Output.field( - _.Output.Nullable($Scalar.Date), - _.Args({ date: _.Input.List(_.Input.Nullable($Scalar.Date)) }), +export const Query = $.Object$(`Query`, { + date: $.field($.Output.Nullable($Scalar.Date)), + dateNonNull: $.field($Scalar.Date), + dateList: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Date)))), + dateObject1: $.field($.Output.Nullable(() => DateObject1)), + dateUnion: $.field($.Output.Nullable(() => DateUnion)), + dateInterface1: $.field($.Output.Nullable(() => DateInterface1)), + dateListNonNull: $.field($.Output.List($Scalar.Date)), + dateArg: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.Nullable($Scalar.Date) })), + dateArgNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $Scalar.Date })), + dateArgList: $.field( + $.Output.Nullable($Scalar.Date), + $.Args({ date: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Date))) }), ), - dateArgNonNullListNonNull: _.Output.field( - _.Output.Nullable($Scalar.Date), - _.Args({ date: _.Input.List($Scalar.Date) }), + dateArgNonNullList: $.field( + $.Output.Nullable($Scalar.Date), + $.Args({ date: $.Input.List($.Input.Nullable($Scalar.Date)) }), ), - dateArgInputObject: _.Output.field(_.Output.Nullable($Scalar.Date), _.Args({ input: _.Input.Nullable(InputObject) })), - interface: _.Output.field(_.Output.Nullable(() => Interface)), - id: _.Output.field(_.Output.Nullable($Scalar.ID)), - idNonNull: _.Output.field($Scalar.ID), - string: _.Output.field(_.Output.Nullable($Scalar.String)), - stringWithRequiredArg: _.Output.field(_.Output.Nullable($Scalar.String), _.Args({ string: $Scalar.String })), - stringWithArgs: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ - string: _.Input.Nullable($Scalar.String), - int: _.Input.Nullable($Scalar.Int), - float: _.Input.Nullable($Scalar.Float), - boolean: _.Input.Nullable($Scalar.Boolean), - id: _.Input.Nullable($Scalar.ID), + dateArgNonNullListNonNull: $.field($.Output.Nullable($Scalar.Date), $.Args({ date: $.Input.List($Scalar.Date) })), + dateArgInputObject: $.field($.Output.Nullable($Scalar.Date), $.Args({ input: $.Input.Nullable(InputObject) })), + interface: $.field($.Output.Nullable(() => Interface)), + id: $.field($.Output.Nullable($Scalar.ID)), + idNonNull: $.field($Scalar.ID), + string: $.field($.Output.Nullable($Scalar.String)), + stringWithRequiredArg: $.field($.Output.Nullable($Scalar.String), $.Args({ string: $Scalar.String })), + stringWithArgs: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ + string: $.Input.Nullable($Scalar.String), + int: $.Input.Nullable($Scalar.Int), + float: $.Input.Nullable($Scalar.Float), + boolean: $.Input.Nullable($Scalar.Boolean), + id: $.Input.Nullable($Scalar.ID), }), ), - stringWithArgEnum: _.Output.field(_.Output.Nullable($Scalar.String), _.Args({ ABCEnum: _.Input.Nullable(ABCEnum) })), - stringWithListArg: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ ints: _.Input.Nullable(_.Input.List(_.Input.Nullable($Scalar.Int))) }), + stringWithArgEnum: $.field($.Output.Nullable($Scalar.String), $.Args({ ABCEnum: $.Input.Nullable(ABCEnum) })), + stringWithListArg: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ ints: $.Input.Nullable($.Input.List($.Input.Nullable($Scalar.Int))) }), ), - stringWithListArgRequired: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ ints: _.Input.List(_.Input.Nullable($Scalar.Int)) }), + stringWithListArgRequired: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ ints: $.Input.List($.Input.Nullable($Scalar.Int)) }), ), - stringWithArgInputObject: _.Output.field( - _.Output.Nullable($Scalar.String), - _.Args({ input: _.Input.Nullable(InputObject) }), + stringWithArgInputObject: $.field( + $.Output.Nullable($Scalar.String), + $.Args({ input: $.Input.Nullable(InputObject) }), ), - stringWithArgInputObjectRequired: _.Output.field(_.Output.Nullable($Scalar.String), _.Args({ input: InputObject })), - listListIntNonNull: _.Output.field(_.Output.List(_.Output.List($Scalar.Int))), - listListInt: _.Output.field( - _.Output.Nullable(_.Output.List(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Int))))), + stringWithArgInputObjectRequired: $.field($.Output.Nullable($Scalar.String), $.Args({ input: InputObject })), + listListIntNonNull: $.field($.Output.List($.Output.List($Scalar.Int))), + listListInt: $.field( + $.Output.Nullable($.Output.List($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int))))), ), - listInt: _.Output.field(_.Output.Nullable(_.Output.List(_.Output.Nullable($Scalar.Int)))), - listIntNonNull: _.Output.field(_.Output.List($Scalar.Int)), - object: _.Output.field(_.Output.Nullable(() => Object1)), - objectNonNull: _.Output.field(() => Object1), - objectNested: _.Output.field(_.Output.Nullable(() => ObjectNested)), - objectWithArgs: _.Output.field( - _.Output.Nullable(() => Object1), - _.Args({ - string: _.Input.Nullable($Scalar.String), - int: _.Input.Nullable($Scalar.Int), - float: _.Input.Nullable($Scalar.Float), - boolean: _.Input.Nullable($Scalar.Boolean), - id: _.Input.Nullable($Scalar.ID), + listInt: $.field($.Output.Nullable($.Output.List($.Output.Nullable($Scalar.Int)))), + listIntNonNull: $.field($.Output.List($Scalar.Int)), + object: $.field($.Output.Nullable(() => Object1)), + objectNonNull: $.field(() => Object1), + objectNested: $.field($.Output.Nullable(() => ObjectNested)), + objectWithArgs: $.field( + $.Output.Nullable(() => Object1), + $.Args({ + string: $.Input.Nullable($Scalar.String), + int: $.Input.Nullable($Scalar.Int), + float: $.Input.Nullable($Scalar.Float), + boolean: $.Input.Nullable($Scalar.Boolean), + id: $.Input.Nullable($Scalar.ID), }), ), - fooBarUnion: _.Output.field(_.Output.Nullable(() => FooBarUnion)), - abcEnum: _.Output.field(_.Output.Nullable(ABCEnum)), - lowerCaseUnion: _.Output.field(_.Output.Nullable(() => lowerCaseUnion)), + fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), + abcEnum: $.field($.Output.Nullable(ABCEnum)), + lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), }) export const $Index = {