Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ts-client): args on interfaces and unions #781

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/client/SelectionSet/SelectionSet.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ test(`Query`, () => {
assertType<Q>({ interface: { __typename: true } })
assertType<Q>({ interface: { __typename: { $defer: true } } })
assertType<Q>({ interface: { $scalars: true } })
assertType<Q>({ interfaceWithArgs: { $: { id: `abc` }, id: true } })
// @ts-expect-error needs fragment
assertType<Q>({ interface: { id: true, int: true } })
// @ts-expect-error needs fragment
Expand Down Expand Up @@ -224,6 +225,8 @@ test(`Query`, () => {
assertType<Q>({ scalars: { $scalars: { $skip: true } } })
// union fragment
assertType<Q>({ fooBarUnion: { onBar: { $scalars: true } } })
assertType<Q>({ unionFooBarWithArgs: { $: { id: `abc` }, onBar: { $scalars: true } } })

// assertType<S>({ scalars: select() })

// todo empty selection set not allowed, with arguments given
Expand Down
4 changes: 2 additions & 2 deletions src/client/SelectionSet/SelectionSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export type Field_<
$type extends Schema.Scalar.Any ? Indicator<$Field> :
$type extends Schema.Enum ? Indicator<$Field> :
$type extends Schema.Object$2 ? Object<$type, $Index> & ($Options['hideDirectives'] extends true ? {} : FieldDirectives) & Arguments<$Field> :
$type extends Schema.Union ? Union<$type, $Index> :
$type extends Schema.Interface ? Interface<$type, $Index> :
$type extends Schema.Union ? Union<$type, $Index> & Arguments<$Field> :
$type extends Schema.Interface ? Interface<$type, $Index> & Arguments<$Field> :
TSError<'Field', '$Field case not handled', { $Field: $Field }>
// dprint-ignore
type Arguments<$Field extends SomeField> =
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type ValidateDocumentOperationNames<$Document> =
string | number extends keyof $Document
? $Document
: keyof { [K in keyof $Document & string as Schema.Named.NameParse<K> extends never ? K : never]: K } extends never
? $Document
? $Document
: TSError<'ValidateDocumentOperationNames', `One or more Invalid operation name in document: ${keyof { [K in keyof $Document & string as Schema.Named.NameParse<K> extends never ? K : never]: K }}`>

// dprint-ignore
Expand Down
14 changes: 14 additions & 0 deletions src/generator/__snapshots__/files.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,20 @@ export namespace Root {
abcEnum: $.Field<$.Output.Nullable<Enum.ABCEnum>, null>
lowerCaseUnion: $.Field<$.Output.Nullable<Union.lowerCaseUnion>, null>
interface: $.Field<$.Output.Nullable<Interface.Interface>, null>
interfaceWithArgs: $.Field<
$.Output.Nullable<Interface.Interface>,
$.Args<{
id: $Scalar.ID
}>
>
interfaceNonNull: $.Field<Interface.Interface, null>
unionFooBar: $.Field<$.Output.Nullable<Union.FooBarUnion>, null>
unionFooBarWithArgs: $.Field<
$.Output.Nullable<Union.FooBarUnion>,
$.Args<{
id: $.Input.Nullable<$Scalar.ID>
}>
>
unionObject: $.Field<$.Output.Nullable<Object.ObjectUnion>, null>
unionFooBarNonNull: $.Field<Union.FooBarUnion, null>
unionObjectNonNull: $.Field<Object.ObjectUnion, null>
Expand Down Expand Up @@ -476,8 +488,10 @@ export const Query = $.Object$(\`Query\`, {
abcEnum: $.field($.Output.Nullable(ABCEnum)),
lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)),
interface: $.field($.Output.Nullable(() => Interface)),
interfaceWithArgs: $.field($.Output.Nullable(() => Interface), $.Args({ id: $Scalar.ID })),
interfaceNonNull: $.field(() => Interface),
unionFooBar: $.field($.Output.Nullable(() => FooBarUnion)),
unionFooBarWithArgs: $.field($.Output.Nullable(() => FooBarUnion), $.Args({ id: $.Input.Nullable($Scalar.ID) })),
unionObject: $.field($.Output.Nullable(() => ObjectUnion)),
unionFooBarNonNull: $.field(() => FooBarUnion),
unionObjectNonNull: $.field(() => ObjectUnion),
Expand Down
12 changes: 12 additions & 0 deletions tests/ts/_/schema/generated/SchemaBuildtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,20 @@ export namespace Root {
abcEnum: $.Field<$.Output.Nullable<Enum.ABCEnum>, null>
lowerCaseUnion: $.Field<$.Output.Nullable<Union.lowerCaseUnion>, null>
interface: $.Field<$.Output.Nullable<Interface.Interface>, null>
interfaceWithArgs: $.Field<
$.Output.Nullable<Interface.Interface>,
$.Args<{
id: $Scalar.ID
}>
>
interfaceNonNull: $.Field<Interface.Interface, null>
unionFooBar: $.Field<$.Output.Nullable<Union.FooBarUnion>, null>
unionFooBarWithArgs: $.Field<
$.Output.Nullable<Union.FooBarUnion>,
$.Args<{
id: $.Input.Nullable<$Scalar.ID>
}>
>
unionObject: $.Field<$.Output.Nullable<Object.ObjectUnion>, null>
unionFooBarNonNull: $.Field<Union.FooBarUnion, null>
unionObjectNonNull: $.Field<Object.ObjectUnion, null>
Expand Down
2 changes: 2 additions & 0 deletions tests/ts/_/schema/generated/SchemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ export const Query = $.Object$(`Query`, {
abcEnum: $.field($.Output.Nullable(ABCEnum)),
lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)),
interface: $.field($.Output.Nullable(() => Interface)),
interfaceWithArgs: $.field($.Output.Nullable(() => Interface), $.Args({ id: $Scalar.ID })),
interfaceNonNull: $.field(() => Interface),
unionFooBar: $.field($.Output.Nullable(() => FooBarUnion)),
unionFooBarWithArgs: $.field($.Output.Nullable(() => FooBarUnion), $.Args({ id: $.Input.Nullable($Scalar.ID) })),
unionObject: $.field($.Output.Nullable(() => ObjectUnion)),
unionFooBarNonNull: $.field(() => FooBarUnion),
unionObjectNonNull: $.field(() => ObjectUnion),
Expand Down
2 changes: 2 additions & 0 deletions tests/ts/_/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ type Query {
lowerCaseUnion: lowerCaseUnion
# Interface
interface: Interface
interfaceWithArgs(id:ID!): Interface
interfaceNonNull: Interface!
# Union
unionFooBar: FooBarUnion
unionFooBarWithArgs(id:ID): FooBarUnion
unionObject: ObjectUnion
unionFooBarNonNull: FooBarUnion!
unionObjectNonNull: ObjectUnion!
Expand Down