From 0366f9e625d1625ac530aa3c7ed1b6ab3dc0a022 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 18 Jan 2024 11:27:56 +0000 Subject: [PATCH 1/5] Omit field args from introspection mapping --- src/introspection.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/introspection.ts b/src/introspection.ts index 4bf4d9af..6fbfef2e 100644 --- a/src/introspection.ts +++ b/src/introspection.ts @@ -136,11 +136,25 @@ type mapEnum = { type: T['enumValues'][number]['name']; }; +type mapField = T extends IntrospectionField + ? { + name: T['name']; + type: T['type']; + args: any; + } + : never; + export type mapObject = { kind: 'OBJECT'; name: T['name']; interfaces: T['interfaces'][number]['name']; - fields: obj>; + fields: obj<{ + [P in T['fields'][number]['name']]: T['fields'][number] extends infer Field + ? Field extends { readonly name: P } + ? mapField + : never + : never; + }>; }; export type mapInputObject = { From 46e0e08dee05eebc6a480110833bfab3e424692c Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 18 Jan 2024 11:28:33 +0000 Subject: [PATCH 2/5] Remove IntrospectionField from ObjectLikeType to avoid excessive match --- src/selection.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/selection.ts b/src/selection.ts index 85308c6c..a2528901 100644 --- a/src/selection.ts +++ b/src/selection.ts @@ -16,7 +16,6 @@ import type { } from './namespace'; import type { - IntrospectionField, IntrospectionListTypeRef, IntrospectionNamedTypeRef, IntrospectionNonNullTypeRef, @@ -27,7 +26,7 @@ import type { type ObjectLikeType = { kind: 'OBJECT' | 'INTERFACE' | 'UNION'; name: string; - fields: { [key: string]: IntrospectionField }; + fields: { [key: string]: any }; }; type _unwrapTypeRec< From 65eadb8708b88fcb3d82dbffb40f45479831af03 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 18 Jan 2024 11:29:37 +0000 Subject: [PATCH 3/5] Add changeset --- .changeset/dry-actors-exercise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dry-actors-exercise.md diff --git a/.changeset/dry-actors-exercise.md b/.changeset/dry-actors-exercise.md new file mode 100644 index 00000000..6849a622 --- /dev/null +++ b/.changeset/dry-actors-exercise.md @@ -0,0 +1,5 @@ +--- +'gql.tada': patch +--- + +Prevent type inference for schemas with “huge” root types (i.e. types with an excessive amount of fields) from failing introspection mapping. From d01378ac656c9c826f5c005a2ce1fe4cbf5caac2 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 18 Jan 2024 11:32:36 +0000 Subject: [PATCH 4/5] Apply identical change to mapInterface --- src/introspection.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/introspection.ts b/src/introspection.ts index 6fbfef2e..b732f305 100644 --- a/src/introspection.ts +++ b/src/introspection.ts @@ -168,7 +168,13 @@ type mapInterface = { name: T['name']; interfaces: T['interfaces'] extends readonly any[] ? T['interfaces'][number]['name'] : never; possibleTypes: T['possibleTypes'][number]['name']; - fields: obj>; + fields: obj<{ + [P in T['fields'][number]['name']]: T['fields'][number] extends infer Field + ? Field extends { readonly name: P } + ? mapField + : never + : never; + }>; }; type mapUnion = { From 1bb0d1bff8096db7736413965c6f427faefc5174 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 18 Jan 2024 11:34:16 +0000 Subject: [PATCH 5/5] Delete mapNames --- src/introspection.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/introspection.ts b/src/introspection.ts index b732f305..bef434bc 100644 --- a/src/introspection.ts +++ b/src/introspection.ts @@ -110,14 +110,6 @@ interface DefaultScalars { Int: number; } -type mapNames = obj<{ - [P in T[number]['name']]: T[number] extends infer Value - ? Value extends { readonly name: P } - ? obj - : never - : never; -}>; - type mapScalar< Type extends IntrospectionScalarType, Scalars extends ScalarsLike = DefaultScalars,