UNPKG

1.41 kBTypeScriptView Raw
1import type { DocumentNode } from "graphql";
2export interface DocumentTypeDecoration<TResult, TVariables> {
3 /**
4 * This type is used to ensure that the variables you pass in to the query are assignable to Variables
5 * and that the Result is assignable to whatever you pass your result to. The method is never actually
6 * implemented, but the type is valid because we list it as optional
7 */
8 __apiType?: (variables: TVariables) => TResult;
9}
10export interface TypedDocumentNode<TResult = {
11 [key: string]: any;
12}, TVariables = {
13 [key: string]: any;
14}> extends DocumentNode, DocumentTypeDecoration<TResult, TVariables> {
15}
16/**
17 * Helper for extracting a TypeScript type for operation result from a TypedDocumentNode and TypedDocumentString.
18 * @example
19 * const myQuery = { ... }; // TypedDocumentNode<R, V>
20 * type ResultType = ResultOf<typeof myQuery>; // Now it's R
21 */
22export type ResultOf<T> = T extends DocumentTypeDecoration<infer ResultType, infer VariablesType> ? ResultType : never;
23/**
24 * Helper for extracting a TypeScript type for operation variables from a TypedDocumentNode and TypedDocumentString.
25 * @example
26 * const myQuery = { ... }; // TypedDocumentNode<R, V>
27 * type VariablesType = VariablesOf<typeof myQuery>; // Now it's V
28 */
29export type VariablesOf<T> = T extends DocumentTypeDecoration<infer ResultType, infer VariablesType> ? VariablesType : never;