Skip to content

Commit

Permalink
fix(ts-client): result types have no args
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Apr 20, 2024
1 parent 512150d commit ee66c10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/client/ResultSet/ResultSet.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ test(`general`, () => {
expectTypeOf<RS<{ object: { id: true } }>>().toEqualTypeOf<{ object: null | { id: string | null } }>()
// non-nullable
expectTypeOf<RS<{ objectNonNull: { id: true } }>>().toEqualTypeOf<{ objectNonNull: { id: string | null } }>()
// with args
expectTypeOf<RS<{ objectWithArgs: { $: { id: 'abc' }; id: true }}>>().toEqualTypeOf<{ objectWithArgs: null | { id: string | null } }>()

// scalars-wildcard
expectTypeOf<RS<{ objectNonNull: { $scalars: true } }>>().toEqualTypeOf<{ objectNonNull: { __typename: "Object1"; string: null|string; int: null|number; float: null|number; boolean: null|boolean; id: null|string } }>()
Expand All @@ -53,6 +55,9 @@ test(`general`, () => {
expectTypeOf<RS<{ fooBarUnion: { onFoo: { __typename: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | {} | { __typename: "Foo" } }>()
expectTypeOf<RS<{ fooBarUnion: { onFoo: { id: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | {} | { id: null|string } }>()
expectTypeOf<RS<{ fooBarUnion: { __typename: true; onFoo: { id: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | { __typename: "Bar" } | { __typename: "Foo"; id: null|string } }>()
// with Args
expectTypeOf<RS<{ unionFooBarWithArgs: { $: { id: `abc` }, onFoo: { id: true } } }>>().toEqualTypeOf<{ unionFooBarWithArgs: null | {} | { id: null|string } }>()


// Union fragments Case
expectTypeOf<RS<{ lowerCaseUnion: { __typename:true, onLowerCaseObject: { id: true }, onLowerCaseObject2: { int: true } } }>>().toEqualTypeOf<{ lowerCaseUnion: null | { __typename: 'lowerCaseObject'; id: null|string } | { __typename: 'lowerCaseObject2'; int: null|number } }>()
Expand All @@ -67,6 +72,8 @@ test(`general`, () => {
expectTypeOf<RS<{ interface: { __typename:true }}>>().toEqualTypeOf<{ interface: null | { __typename: 'Object1ImplementingInterface' } | { __typename: 'Object2ImplementingInterface' } }>()
expectTypeOf<RS<{ interface: { onObject1ImplementingInterface: { __typename: true } }}>>().toEqualTypeOf<{ interface: null | { __typename: 'Object1ImplementingInterface' } | {}}>()
expectTypeOf<RS<{ interface: { $scalars: true }}>>().toEqualTypeOf<{ interface: null | { __typename: 'Object1ImplementingInterface', id: null | string, int: null|number} | { __typename: 'Object2ImplementingInterface', id: null | string; boolean:null|boolean} }>()
// with args
expectTypeOf<RS<{ interfaceWithArgs: { $:{id:'abc'}; id: true }}>>().toEqualTypeOf<{ interfaceWithArgs: null | { id: null | string } }>()

// Alias
// scalar
Expand Down
4 changes: 2 additions & 2 deletions src/client/ResultSet/ResultSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export type Field<$SelectionSet, $Field extends SomeField, $Index extends Schema
(
| FieldDirectiveInclude<$SelectionSet>
| FieldDirectiveSkip<$SelectionSet>
| FieldType<$SelectionSet, $Field['type'], $Index>
| FieldType<Omit<$SelectionSet, '$'>, $Field['type'], $Index>
)

// dprint-ignore
type FieldType<
$SelectionSet,
$Type extends Schema.Output.Any,
$Index extends Schema.Index
> =Simplify<
> = Simplify<
$Type extends Schema.__typename<infer $Value> ? $Value :
$Type extends Schema.Output.Nullable<infer $InnerType> ? null | FieldType<$SelectionSet, $InnerType, $Index> :
$Type extends Schema.Output.List<infer $InnerType> ? Array<FieldType<$SelectionSet, $InnerType, $Index>> :
Expand Down

0 comments on commit ee66c10

Please sign in to comment.