import { Operation, FetchResult, Observable, GraphQLRequest, ApolloLink } from '@apollo/client'; import { MockedResponse } from '@apollo/client/testing'; import { DocumentNode } from 'graphql'; export { withApolloMocks, hookWrapperWithApolloMocks, HookWrapperAndLink, WildcardMockOptions, MockLinkAndElement, } from './utils'; export declare const MATCH_ANY_PARAMETERS: unique symbol; export declare type GraphQLVariables = Record; export interface GraphQLRequestWithWildcard extends Omit { variables?: GraphQLRequest['variables'] | typeof MATCH_ANY_PARAMETERS; } interface MockedResponseWithMatchCount extends Omit { /** Use Number.POSITIVE_INFINITY to allow infinite matches */ nMatches?: number; result?: FetchResult | ((variables?: GraphQLVariables) => FetchResult); } declare type WildcardMock = Omit & { request: GraphQLRequest; }; export interface WildcardMockedResponse extends Omit, 'result'> { request: GraphQLRequestWithWildcard; result?: FetchResult | ((variables?: GraphQLVariables) => FetchResult); } export declare type MockedResponses = readonly WildcardMockedResponse[]; interface Act { (fun: () => Promise): Promise; (fun: () => void): void; } export interface WildcardMockLinkOptions { addTypename?: boolean; act?: Act; suppressMissingMockWarnings?: boolean; } interface StoredOperation { query: DocumentNode; variables: GraphQLVariables; context: GraphQLVariables; } /** * Extends MockLink to provide the ability to match request queries independent * of their variables and have them match 1 or more responses. Also stores the * last request for use in assertion frameworks. */ export declare class WildcardMockLink extends ApolloLink { options: boolean | WildcardMockLinkOptions; private wildcardMatches; private regularMatches; queries: StoredOperation[]; mutations: StoredOperation[]; subscriptions: StoredOperation[]; get lastQuery(): StoredOperation | undefined; get lastMutation(): StoredOperation | undefined; get lastSubscription(): StoredOperation | undefined; private pendingResponses; private lastResponse?; private act; addTypename: boolean; suppressMissingMockWarnings: boolean; private openSubscriptions; constructor(mockedResponses: MockedResponses, options?: boolean | WildcardMockLinkOptions); request(op: Operation): Observable | null; requestSubscription(op: Operation): Observable | null; /** * Send a new response to the open subscription matching `request`. This does not * work for subscriptions that matched wildcard requests. */ sendSubscriptionResult(request: DocumentNode, variables: GraphQLVariables | undefined, response: FetchResult): void; /** * Send a new response to the open subscription matching `request`. This only * works for subscriptions that matched wildcard requests. */ sendWildcardSubscriptionResult(request: DocumentNode, response: FetchResult): void; /** * Close the subscription matching `request`. */ closeSubscription(request: DocumentNode): void; addMockedResponse(...responses: MockedResponses): void; /** * Remove the wildcard mocked response for `request`. */ removeWildcardMockedResponse(request: DocumentNode): void; /** * Return true if the last query request matches the argument. */ lastQueryMatches(request: DocumentNode): boolean; /** * Return true if the last query request matches the argument. */ lastMutationMatches(request: DocumentNode): boolean; /** * Return true if the last subscription request matches the argument. */ lastSubscriptionMatches(request: DocumentNode): boolean; /** * Wait for the response of the last query or mutation. * It cannot wait for responses from subscriptions because they remain open. */ waitForLastResponse(): Promise; /** * Wait for the all responses that are currently pending. */ waitForAllResponses(): Promise; /** * Wait for all responses that are currently pending, and all responses that are triggered * as a result of those responses being sent. * @param requestWindow How long to wait between between requests for a new request to be * made, by default use 0 which allows one tick. */ waitForAllResponsesRecursively(requestWindow?: number): Promise; private queryToString; private queryAndVariablesToString; /** * Get wildcard mock match, if it exists, also removing the mock (or * decrementing its match count) as necessary. */ private getWildcardMockMatch; private getRegularMockMatch; private setLastResponsePromiseFromObservable; }