-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts): support input object in selection set (#736)
- Loading branch information
1 parent
0d1e1a6
commit f9ad67a
Showing
19 changed files
with
308 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,51 @@ | ||
import type { TSError } from '../../lib/TSError.js' | ||
import type { NamedType } from '../NamedType/__.js' | ||
|
||
export interface __typename<$Type extends string = string> { | ||
kind: 'typename' | ||
type: $Type | ||
} | ||
export interface Nullable<$Type extends Any> { | ||
kind: 'nullable' | ||
type: $Type | ||
} | ||
export interface List<$Type extends Any> { | ||
kind: 'list' | ||
type: $Type | ||
export namespace Base { | ||
export interface Nullable<$Type> { | ||
kind: 'nullable' | ||
type: $Type | ||
} | ||
export interface List<$Type> { | ||
kind: 'list' | ||
type: $Type | ||
} | ||
} | ||
|
||
export type Any = List<any> | __typename<any> | Nullable<any> | NamedType.Any | ||
export namespace Output { | ||
export interface __typename<$Type extends string = string> { | ||
kind: 'typename' | ||
type: $Type | ||
} | ||
export type Nullable<$Type extends Any> = Base.Nullable<$Type> | ||
export type List<$Type extends Any> = Base.List<$Type> | ||
|
||
export type Any = Output.List<any> | __typename<any> | Base.Nullable<any> | NamedType.AnyOutput | ||
|
||
export const __typename = <$Type extends string>(type: $Type): __typename<$Type> => ({ kind: `typename`, type }) | ||
export const nullable = <$Type extends __typename<any> | List<any>>(type: $Type): Nullable<$Type> => ({ | ||
kind: `nullable`, | ||
type, | ||
}) | ||
export const list = <$Type extends Any>(type: $Type): List<$Type> => ({ kind: `list`, type }) | ||
export const __typename = <$Type extends string>(type: $Type): __typename<$Type> => ({ kind: `typename`, type }) | ||
export const nullable = <$Type extends __typename<any> | List<any>>(type: $Type): Nullable<$Type> => ({ | ||
kind: `nullable`, | ||
type, | ||
}) | ||
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> = | ||
// todo extends any because of infinite depth issue in generated schema types | ||
// dprint-ignore | ||
export type Unwrap<$Type extends any> = | ||
$Type extends List<infer $innerType> ? Unwrap<$innerType> : | ||
$Type extends Nullable<infer $innerType> ? Unwrap<$innerType> : | ||
$Type extends __typename ? $Type['type'] : | ||
$Type extends NamedType.Any ? $Type : | ||
$Type extends NamedType.AnyOutput ? $Type : | ||
TSError<'Unwrap', 'Unknown $Type', { $Type: $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 unwrap = <$Type extends Any>(type: $Type): Unwrap<$Type> => { | ||
// @ts-expect-error fixme | ||
return type.kind === `named` ? type.type : unwrap(type.type) | ||
} | ||
} | ||
|
||
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<any> | Nullable<any> | NamedType.AnyInput | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
|
||
type Fields = Record<string, any> | ||
|
||
export interface InputObject< | ||
$Name extends string = string, | ||
$Fields extends Fields = Fields, | ||
> { | ||
kind: 'InputObject' | ||
name: $Name | ||
fields: $Fields | ||
} | ||
|
||
export const InputObject = <$Name extends string, $Fields extends Record<keyof $Fields, any>>( | ||
name: $Name, | ||
fields: $Fields, | ||
): InputObject<$Name, $Fields> => ({ | ||
kind: `InputObject`, | ||
name: name, | ||
fields: { | ||
...fields, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.