From 1238a1c8266651b82b862fce11e2164f2651a20d Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Sun, 14 Apr 2024 17:16:10 -0400 Subject: [PATCH] fix(ts-client): thunk list objects --- src/Schema/Output/types/List.ts | 7 ++++--- src/generator/__snapshots__/files.test.ts.snap | 4 ++++ tests/ts/_/schema/generated/SchemaBuildtime.ts | 2 ++ tests/ts/_/schema/generated/SchemaRuntime.ts | 2 ++ tests/ts/_/schema/schema.graphql | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Schema/Output/types/List.ts b/src/Schema/Output/types/List.ts index 8606db9c1..9efc7d216 100644 --- a/src/Schema/Output/types/List.ts +++ b/src/Schema/Output/types/List.ts @@ -1,4 +1,4 @@ -import type { Base } from '../../core/helpers.js' +import type { Base, MaybeThunk } from '../../core/helpers.js' import type { Named } from '../typeGroups.js' import type { Nullable } from './Nullable.js' @@ -6,7 +6,8 @@ type InnerType = Named | Nullable | List export type List<$Type extends InnerType> = Base.List<$Type> -export const List = <$Type extends InnerType>(type: $Type): List<$Type> => ({ +export const List = <$Type extends InnerType>(type: MaybeThunk<$Type>): List<$Type> => ({ kind: `list`, - type, + // at type level "type" is not a thunk + type: type as any, // eslint-disable-line }) diff --git a/src/generator/__snapshots__/files.test.ts.snap b/src/generator/__snapshots__/files.test.ts.snap index e1d92c2ba..24ee36928 100644 --- a/src/generator/__snapshots__/files.test.ts.snap +++ b/src/generator/__snapshots__/files.test.ts.snap @@ -123,6 +123,8 @@ export namespace Root { }> > fooBarUnion: $.Field<$.Output.Nullable, null> + objectList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable>>, null> + objectListNonNull: $.Field<$.Output.List, null> /** * Query enum field documentation. */ @@ -422,6 +424,8 @@ export const Query = $.Object$(\`Query\`, { }), ), fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), + objectList: $.field($.Output.Nullable($.Output.List($.Output.Nullable(() => Object1)))), + objectListNonNull: $.field($.Output.List(() => Object1)), abcEnum: $.field($.Output.Nullable(ABCEnum)), lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), interface: $.field($.Output.Nullable(() => Interface)), diff --git a/tests/ts/_/schema/generated/SchemaBuildtime.ts b/tests/ts/_/schema/generated/SchemaBuildtime.ts index facf538e5..93c6a01d2 100644 --- a/tests/ts/_/schema/generated/SchemaBuildtime.ts +++ b/tests/ts/_/schema/generated/SchemaBuildtime.ts @@ -120,6 +120,8 @@ export namespace Root { }> > fooBarUnion: $.Field<$.Output.Nullable, null> + objectList: $.Field<$.Output.Nullable<$.Output.List<$.Output.Nullable>>, null> + objectListNonNull: $.Field<$.Output.List, null> /** * Query enum field documentation. */ diff --git a/tests/ts/_/schema/generated/SchemaRuntime.ts b/tests/ts/_/schema/generated/SchemaRuntime.ts index 3b88e0b68..80a15fd5f 100644 --- a/tests/ts/_/schema/generated/SchemaRuntime.ts +++ b/tests/ts/_/schema/generated/SchemaRuntime.ts @@ -143,6 +143,8 @@ export const Query = $.Object$(`Query`, { }), ), fooBarUnion: $.field($.Output.Nullable(() => FooBarUnion)), + objectList: $.field($.Output.Nullable($.Output.List($.Output.Nullable(() => Object1)))), + objectListNonNull: $.field($.Output.List(() => Object1)), abcEnum: $.field($.Output.Nullable(ABCEnum)), lowerCaseUnion: $.field($.Output.Nullable(() => lowerCaseUnion)), interface: $.field($.Output.Nullable(() => Interface)), diff --git a/tests/ts/_/schema/schema.graphql b/tests/ts/_/schema/schema.graphql index 80cb9fe33..dba7e5d92 100644 --- a/tests/ts/_/schema/schema.graphql +++ b/tests/ts/_/schema/schema.graphql @@ -33,6 +33,8 @@ type Query { objectNested: ObjectNested objectWithArgs(string:String, int:Int, float:Float, boolean:Boolean, id:ID): Object1 fooBarUnion: FooBarUnion + objectList: [Object1] + objectListNonNull: [Object1!]! """ Query enum field documentation. """