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. diff --git a/src/introspection.ts b/src/introspection.ts index 4bf4d9af..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, @@ -136,11 +128,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 = { @@ -154,7 +160,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 = { 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<