import { ApolloClient } from "@apollo/client"; import type { NormalizedCacheObject, InMemoryCacheConfig } from "@apollo/client"; import type { DocumentNode, ExecutionResult, GraphQLSchema } from "graphql"; export interface RequestDescriptor { readonly node: Node; readonly variables: Record; readonly context?: Record; } export interface OperationDescriptor { readonly schema: Schema; readonly request: RequestDescriptor; } type OperationMockResolver = (operation: OperationDescriptor) => ExecutionResult | Error | undefined | null; export interface MockFunctions { /** * Get all operation executed during the test by the current time. */ getAllOperations(): OperationDescriptor[]; /** * Return the most recent operation. This method will throw if no operations were executed prior this call. */ getMostRecentOperation(): OperationDescriptor; /** * Find a particular operation in the list of all executed operations. This method will throw if the operation is not * found. */ findOperation(findFn: (operation: OperationDescriptor) => boolean): OperationDescriptor; /** * Provide a payload for an operation, but not complete the request. Practically useful when testing incremental * updates and subscriptions. * * @note * * ApolloClient requires a delay until the next tick of the runloop before it updates, * as per https://www.apollographql.com/docs/react/development-testing/testing/ */ nextValue(operation: OperationDescriptor, data: ExecutionResult): Promise; /** * Complete the operation. No more payloads are expected for this operation. * * @note * * ApolloClient requires a delay until the next tick of the runloop before it updates, * as per https://www.apollographql.com/docs/react/development-testing/testing/ */ complete(operation: OperationDescriptor): Promise; /** * Resolve the request with the provided payload. This is a shortcut for `nextValue(...)` and `complete(...)`. * * @note * * ApolloClient requires a delay until the next tick of the runloop before it updates, * as per https://www.apollographql.com/docs/react/development-testing/testing/ */ resolve(operation: OperationDescriptor, data: ExecutionResult): Promise; /** * Reject the request with a given error. * * @note * * ApolloClient requires a delay until the next tick of the runloop before it updates, * as per https://www.apollographql.com/docs/react/development-testing/testing/ */ reject(operation: OperationDescriptor, error: Error): Promise; /** * A shortcut for `getMostRecentOperation()` and `resolve()`. * * @note * * ApolloClient requires a delay until the next tick of the runloop before it updates, * as per https://www.apollographql.com/docs/react/development-testing/testing/ */ resolveMostRecentOperation(resolver: (operation: OperationDescriptor) => ExecutionResult | Promise): Promise; /** * A shortcut for `getMostRecentOperation()` and `reject()`. * @note * * ApolloClient requires a delay until the next tick of the runloop before it updates, * as per https://www.apollographql.com/docs/react/development-testing/testing/ */ rejectMostRecentOperation(error: Error | ((operation: OperationDescriptor) => Error)): Promise; /** * Adds a resolver function that will be used to resolve/reject operations as they appear. */ queueOperationResolver: (resolver: OperationMockResolver) => Promise; } interface ApolloClientExtension { mock: MockFunctions; } export interface ApolloMockClient extends ApolloClient, ApolloClientExtension { } export declare function createMockClient(schema: GraphQLSchema, options?: { cache?: InMemoryCacheConfig; }): ApolloMockClient; export {}; //# sourceMappingURL=index.d.ts.map