diff --git a/codegen/src/render.ts b/codegen/src/render.ts index 4a66dad..66a6008 100644 --- a/codegen/src/render.ts +++ b/codegen/src/render.ts @@ -70,7 +70,7 @@ export const render = (sdl: string): string => { selectionSet } from '@timkendall/tql' - export type { Result, Variables } from '@timkendall/tql' + export type { Result, SelectionResult, Variables } from '@timkendall/tql' export { $ } from '@timkendall/tql' ` + diff --git a/src/Result.ts b/src/Result.ts index 2a15376..be61888 100644 --- a/src/Result.ts +++ b/src/Result.ts @@ -1,6 +1,8 @@ +import { ResultOf, TypedDocumentNode } from "@graphql-typed-document-node/core"; import { L, Test } from "ts-toolbelt"; import type { Field, InlineFragment, NamedType, Selection, SelectionSet } from "./AST"; +import type { Selection as SchemaSelection } from "./Selection" // @note `Result` takes a root `Type` (TS) and `SelectionSet` (GQL) and recursively walks the // array of `Selection` nodes's (i.e `Field`, `InlineFragment`, or `FragmentSpread` nodes) @@ -81,3 +83,9 @@ type HasInlineFragment | undefined> = T extends Sele : never; type Merge = Omit & N; + +export type SelectionResult = + TSelection extends { toQuery(opts: any): TypedDocumentNode } + ? ResultType + : never; +