diff --git a/src/api.ts b/src/api.ts index 0d95631c..54c24c5e 100644 --- a/src/api.ts +++ b/src/api.ts @@ -2,7 +2,7 @@ import { parse as _parse } from '@0no-co/graphql.web'; import type { stringLiteral } from './utils'; import type { parseDocument } from './parser'; -function parse>(input: Input): parseDocument { +function parse>(input: In): parseDocument { return _parse(input) as any; } diff --git a/src/fragments.ts b/src/fragments.ts index 2ccf182f..1a1aa3f8 100644 --- a/src/fragments.ts +++ b/src/fragments.ts @@ -1,4 +1,5 @@ import type { Kind } from '@0no-co/graphql.web'; +import type { DocumentNodeLike } from './parser'; type _getFragmentMapRec = Definitions extends readonly [ infer Definition, @@ -10,5 +11,6 @@ type _getFragmentMapRec = Definitions extends readonly [ _getFragmentMapRec : {}; -export type getFragmentMap = - _getFragmentMapRec; +export type getFragmentMap = _getFragmentMapRec< + Document['definitions'] +>; diff --git a/src/parser.ts b/src/parser.ts index bcf03540..6f108d24 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -506,4 +506,9 @@ type parseType = takeType> extends [infer Node, string] ? No type parseOperation = TakeOperation> extends [infer Node, string] ? Node : void; +export type DocumentNodeLike = { + kind: Kind.DOCUMENT; + definitions: any[]; +}; + export type { parseConstValue, parseOperation, parseDocument, parseValue, parseType }; diff --git a/src/selection.ts b/src/selection.ts index 4b5af444..da67ae39 100644 --- a/src/selection.ts +++ b/src/selection.ts @@ -9,6 +9,7 @@ import type { import type { tada } from './namespace'; import type { obj, objValues } from './utils'; import type { getFragmentMap } from './fragments'; +import type { DocumentNodeLike } from './parser'; import type { IntrospectionField, @@ -217,7 +218,7 @@ type getDefinitionSelectionRec< : {}; type getDocumentType< - Document extends { kind: Kind.DOCUMENT; definitions: any[] }, + Document extends DocumentNodeLike, Introspection extends IntrospectionLikeType, Fragments extends { [name: string]: any } = {}, > = getDefinitionSelectionRec< @@ -227,7 +228,7 @@ type getDocumentType< >; type getFragmentType< - Document extends { kind: Kind.DOCUMENT; definitions: any[] }, + Document extends DocumentNodeLike, Introspection extends IntrospectionLikeType, Fragments extends { [name: string]: any } = {}, > = Document['definitions'][0] extends {