import { DocumentNode, GraphQLError, ExecutionResult } from 'graphql'; import { Ref, App, MaybeRefOrGetter, InjectionKey } from 'vue'; interface DocumentDecoration { /** Type to support `@graphql-typed-document-node/core` * @internal */ __apiType?: (variables: Variables) => Result; /** Type to support `TypedQueryDocumentNode` from `graphql` * @internal */ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result; } interface GraphQLResponse { data: TData; errors: any; } interface FetchOptions extends RequestInit { url?: string; headers: NonNullable>; } interface ParsedResponse { ok: boolean; status: number; statusText: string; headers: Headers; body: GraphQLResponse | null; } interface Operation { query: string | DocumentNode | DocumentDecoration; variables?: TVars; } type QueryVariables = Record; declare function parseResponse(response: Response): Promise>; declare function mergeFetchOpts(lhs: FetchOptions, rhs: FetchOptions): { method: string; headers: { [x: string]: string; }; url?: string; body?: BodyInit | null; cache?: RequestCache; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; redirect?: RequestRedirect; referrer?: string; referrerPolicy?: ReferrerPolicy; signal?: AbortSignal | null; window?: null; }; declare function makeFetchOptions({ query, variables }: Operation, opts: FetchOptions): { method: string; headers: { [x: string]: string; }; url?: string; body?: BodyInit | null; cache?: RequestCache; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; redirect?: RequestRedirect; referrer?: string; referrerPolicy?: ReferrerPolicy; signal?: AbortSignal | null; window?: null; }; /** * Normalizes a query string or object to a string. */ declare function normalizeQuery(query: string | DocumentNode | DocumentDecoration): string | null; declare class CombinedError extends Error { name: 'CombinedError'; message: string; response: any; networkError?: Error; graphqlErrors?: GraphQLError[]; constructor({ response, networkError, graphqlErrors, }: { response: any; networkError?: Error; graphqlErrors?: Array; }); get isGraphQLError(): boolean; toString(): string; } interface OperationResult { data: TData | null; error: CombinedError | null; } type CachePolicy = 'cache-and-network' | 'network-only' | 'cache-first' | 'cache-only'; type StandardOperationResult = ExecutionResult; type MaybePromise = T | Promise; interface ObserverLike { next: (value: T) => void; error: (err: any) => void; complete: () => void; } interface Unsubscribable { unsubscribe: () => void; } /** An abstract observable interface conforming to: https://github.com/tc39/proposal-observable */ interface ObservableLike { subscribe(observer: ObserverLike): Unsubscribable; } type OperationType = 'query' | 'mutation' | 'subscription'; type AfterQueryCallback = (result: OperationResult, ctx: { response?: ParsedResponse; }) => void | Promise; interface QueryOperation extends Operation { type: 'query'; cachePolicy?: CachePolicy; tags?: string[]; } interface MutationOperation extends Operation { type: 'mutation'; clearCacheTags?: string[]; } interface SubscriptionOperation extends Operation { type: 'subscription'; } type OperationWithCachePolicy = QueryOperation | MutationOperation | SubscriptionOperation; type ClientPluginOperation = OperationWithCachePolicy & { key: number; }; interface QueryExecutionContext { headers: Record; } interface ClientPluginContext { useResult: (result: OperationResult, terminate?: boolean) => void; afterQuery: (cb: AfterQueryCallback) => void; operation: ClientPluginOperation; opContext: FetchOptions; response?: ParsedResponse; } type ClientPlugin = ({ useResult, operation }: ClientPluginContext) => void | Promise; type QueryPredicateOrSignal = boolean | Ref | ((variables: TVars) => boolean); interface ClientOptions { url: string; cachePolicy?: CachePolicy; use?: ClientPlugin[]; } /** * Sets or unsets the active client * * @param client - villus client instance */ declare const setActiveClient: (client: Client | undefined) => Client; /** * Get the currently active client if there is any. */ declare const getActiveClient: () => any; type OnResultChangedCallback = (result: OperationResult) => unknown; declare const defaultPlugins: () => ClientPlugin[]; declare class Client { install: (app: App) => void; private url; private defaultCachePolicy; private plugins; private taggedQueries; constructor(opts: ClientOptions); /** * Executes an operation and returns a normalized response. */ private execute; executeQuery(operation: Omit, 'type'>, queryContext?: QueryExecutionContext, onResultChanged?: OnResultChangedCallback): Promise>; executeMutation(operation: Omit, 'type'>, queryContext?: QueryExecutionContext): Promise>; executeSubscription(operation: Omit, 'type'>): Promise>>; registerTaggedQuery(tags: string[], refetch: () => Promise): symbol; unregisterTaggedQuery(id: symbol): void; refetchTaggedQueries(tags: string[]): Promise; } declare function createClient(opts: ClientOptions): Client; declare function useClient(opts: ClientOptions): Client; declare function getQueryKey(operation: Operation, ...components: string[]): number; interface QueryCompositeOptions { query: MaybeRefOrGetter['query']>; variables?: MaybeRefOrGetter; context?: MaybeRefOrGetter; cachePolicy?: CachePolicy; fetchOnMount?: boolean; client?: Client; paused?: QueryPredicateOrSignal; skip?: QueryPredicateOrSignal; tags?: string[]; onData?: (data: TData) => void; onError?: (err: CombinedError) => void; } interface QueryExecutionOpts { cachePolicy: CachePolicy; variables: TVars; } type DataHookHandler = (data: TData) => unknown; type ErrorHookHandler = (error: CombinedError) => unknown; type UnregisterHookFn = () => void; interface BaseQueryApi { data: Ref; isFetching: Ref; isDone: Ref; error: Ref; onData(handler: DataHookHandler): UnregisterHookFn; onError(handler: ErrorHookHandler): UnregisterHookFn; execute(overrideOpts?: Partial>): Promise<{ data: TData | null; error: CombinedError | null; }>; } type DataMapper = (value: OperationResult) => TResult; interface QueryApi extends BaseQueryApi { then(onFulfilled: (value: BaseQueryApi) => any): Promise>; } declare function useQuery(opts: QueryCompositeOptions, mapData?: DataMapper): QueryApi; interface MutationExecutionOptions { context: MaybeRefOrGetter; client?: Client; clearCacheTags?: string[]; refetchTags?: string[]; onData?: (data: TData) => void; onError?: (err: CombinedError) => void; } interface MutationResult { data: TData | null; error: CombinedError | null; } interface MutationApi { data: Ref; isFetching: Ref; isDone: Ref; error: Ref; execute(vars?: TVars): Promise>; } declare function useMutation(query: Operation['query'], opts?: Partial>): MutationApi; interface SubscriptionCompositeOptions { query: MaybeRefOrGetter['query']>; variables?: MaybeRefOrGetter; skip?: QueryPredicateOrSignal; paused?: QueryPredicateOrSignal; client?: Client; initialData?: TResult; subscribeOnMount?: boolean; unsubscribeOnUnmount?: boolean; } type Reducer = (value: OperationResult, prev: TResult | null) => TResult; interface SubscriptionReturns { data: Ref; error: Ref; paused: Ref; isFetching: Ref; subscribe: () => void; unsubscribe: () => void; isSubscribed: () => boolean; } declare function useSubscription(opts: SubscriptionCompositeOptions, reduce?: Reducer): SubscriptionReturns; type SubscriptionForwarder = (operation: Omit & { query: string; }) => MaybePromise>>; declare function handleSubscriptions(forwarder: SubscriptionForwarder): ClientPlugin; interface FetchPluginOpts { fetch?: (typeof window)['fetch']; } declare function fetch(opts?: FetchPluginOpts): ClientPlugin; declare function cache(): ClientPlugin & { clearCache(tags?: string | string[]): void; }; declare function dedup(): ClientPlugin; declare function definePlugin(fn: ClientPlugin): ClientPlugin; declare const VILLUS_CLIENT: InjectionKey; export { type AfterQueryCallback, type BaseQueryApi, type CachePolicy, Client, type ClientOptions, type ClientPlugin, type ClientPluginContext, type ClientPluginOperation, CombinedError, type DataHookHandler, type DocumentDecoration, type ErrorHookHandler, type FetchOptions, type GraphQLResponse, type MaybePromise, type MutationApi, type MutationOperation, type MutationResult, type ObservableLike, type ObserverLike, type Operation, type OperationResult, type OperationType, type OperationWithCachePolicy, type ParsedResponse, type QueryApi, type QueryCompositeOptions, type QueryExecutionContext, type QueryExecutionOpts, type QueryOperation, type QueryPredicateOrSignal, type QueryVariables, type Reducer, type StandardOperationResult, type SubscriptionForwarder, type SubscriptionOperation, type Unsubscribable, VILLUS_CLIENT, cache, createClient, dedup, defaultPlugins, definePlugin, fetch, getActiveClient, getQueryKey, handleSubscriptions, makeFetchOptions, mergeFetchOpts, normalizeQuery, parseResponse, setActiveClient, useClient, useMutation, useQuery, useSubscription };