import type { VariableDefinitionNode } from 'graphql'; import type { TypedDocumentNode, QueryOptions, MutationOptions, SubscriptionOptions, DefaultContext } from '@apollo/client'; import type { DocumentType } from './constants'; export interface IDocumentDefinition { type: DocumentType; name: string; variables: ReadonlyArray; } export interface TypedQueryDocumentNode extends TypedDocumentNode { /** * This is used to ensure that RegistGraphql type set correctly */ __documentType: DocumentType.Query; } export interface TypedMutationDocumentNode extends TypedDocumentNode { /** * This is used to ensure that RegistGraphql type set correctly */ __documentType: DocumentType.Mutation; } export interface TypedSubscriptionDocumentNode extends TypedDocumentNode { /** * This is used to ensure that RegistGraphql type set correctly */ __documentType: DocumentType.Subscription; } export interface RequestCustomConfig { } export interface ObserverOptions { onData: (data?: TData | null) => void; onError?: (err: unknown) => void; onComplete?: () => void; } export type DefaultRegistGraphqlDefinition = Record; export type RegistGraphql> = DefaultRegistGraphqlDefinition> = { [P in keyof C]: C[P] extends TypedQueryDocumentNode ? (options?: Omit, 'query' | 'variables'> & RequestCustomConfig & (TVariables extends null | undefined ? { variables?: NonNullable; } : { variables: TVariables; })) => Promise : C[P] extends TypedMutationDocumentNode ? (options?: Omit, 'mutation' | 'variables'> & RequestCustomConfig & (TVariables extends null | undefined ? { variables?: NonNullable; } : { variables: TVariables; })) => Promise : C[P] extends TypedSubscriptionDocumentNode ? (options?: Omit, 'query' | 'variables'> & ObserverOptions & (TVariables extends null | undefined ? { variables?: NonNullable; } : { variables: TVariables; })) => () => void : (options?: RequestCustomConfig & { variables?: any; }) => Promise; }; /** * plugin options */ type OptionsInPlugin> = {} & O; export interface RegisterPluginContext> = DefaultRegistGraphqlDefinition> { /** * regist graphql */ registGraphqls: RegistGraphql; } /** * Custom registApis properties extends from plugin */ export interface RegistGraphqlCustomProperties> = DefaultRegistGraphqlDefinition> { } /** * plugin definition */ export interface PluginDefinition, C extends Record> = DefaultRegistGraphqlDefinition> { (options?: OptionsInPlugin): (context: RegisterPluginContext) => RegistGraphql & RegistGraphqlCustomProperties; } export {};