import type { FastifyInstance } from 'fastify'; import type { IncomingHttpHeaders } from 'http'; import { DocumentNode, GraphQLError } from 'graphql'; import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; export type GQLResponse = { data: T; errors?: GraphQLError[]; }; export type QueryOptions | undefined = undefined> = { operationName?: string | null; headers?: IncomingHttpHeaders; cookies?: Record; variables?: TVariables; }; export declare function createMercuriusTestClient( /** * Fastify instance, in which it should have been already registered `mercurius`. */ app: FastifyInstance, /** * Global Options for the client, including: * - headers * - url * - cookies */ opts?: { /** * Global Headers added to every query in this test client. */ headers?: IncomingHttpHeaders; /** * GraphQL Endpoint registered on the Fastify instance. * By default is `/graphql` */ url?: string; /** * Global Cookies added to every query in this test client. */ cookies?: Record; }): { /** * Query function. * * @param query Query to be sent. It can be a DocumentNode or string. * @param queryOptions Query specific options, including: * - variables * - operationName * - headers * - cookies */ query: = Record, TVariables extends Record | undefined = undefined>(query: TypedDocumentNode | DocumentNode | string, queryOptions?: QueryOptions) => Promise>; /** * Mutation function. * * @param mutation Mutation to be sent. It can be a DocumentNode or string. * @param mutationOptions Query specific options, including: * - variables * - operationName * - headers * - cookies */ mutate: = Record, TVariables extends Record | undefined = undefined>(mutation: TypedDocumentNode | DocumentNode | string, mutationOptions?: QueryOptions) => Promise>; /** * Returns federated entity by provided typename and keys * @param options * @returns Promise with requested _Entity */ getFederatedEntity: = Record>(options: { typename: string; keys: Record; typeQuery: string; }) => Promise; /** * Set new global headers to this test client instance. * @param newHeaders new Global headers to be set for the test client. */ setHeaders: (newHeaders: IncomingHttpHeaders) => void; /** * Set new global cookies to this test client instance. * @param newCookies new Global headers to be set for the test client. */ setCookies: (newCookies: Record) => void; /** * Send a batch of queries, make sure to enable `allowBatchedQueries`. * * https://github.com/mercurius-js/mercurius#batched-queries * * * @param queries Queries to be sent in batch. * @param queryOptions Cookies | headers to be set. */ batchQueries: (queries: { query: DocumentNode | string; variables?: Record; operationName?: string; }[], queryOptions?: Pick) => Promise[]>; /** * Global headers added to every request in this test client. */ headers: IncomingHttpHeaders; /** * Global cookies added to every request in this test client. */ cookies: Record; /** * GraphQL Subscription */ subscribe: = Record, TVariables extends Record | undefined = undefined>(opts: { /** * Subscription query, can be a DocumentNode or string */ query: string | DocumentNode | TypedDocumentNode; /** * Initial payload, usually for authorization */ initPayload?: (() => Record | Promise>) | Record; /** * Subscription data function */ onData(response: GQLResponse): void; /** * Subscription specific headers */ headers?: IncomingHttpHeaders; /** * Subscription specific cookies */ cookies?: Record; /** * query operationName */ operationName?: string | null; /** * subscription variables */ variables?: TVariables; }) => Promise<{ unsubscribe: () => void; }>; };