/** * GraphQL helper. Wraps a `Misina` instance with `query` / `mutate` * methods that send the canonical `{ query, variables }` envelope. * * Optional Apollo Automatic Persisted Queries (APQ): the client sends * the SHA-256 hash of the query first; the server returns * `PersistedQueryNotFound` if it hasn't seen it yet, and the client * retries with the full query attached. * * Optional GET fallback: short queries can be sent as GET (URL-encoded) * to take advantage of CDN caching. Auto-disabled for mutations and * for queries above ~1500 chars (URL length safety). * * Note: GraphQL doesn't fit the misina plugin shape because it returns a * different surface (`GraphqlClient`), not a `Misina`. Use it as a sibling * helper layered on top of a misina instance. * * @example * ```ts * import { createMisina } from "misina" * import { createGraphqlClient } from "misina/graphql" * * const misina = createMisina({ baseURL }) * const gql = createGraphqlClient(misina, { endpoint: "/graphql" }) * const data = await gql.query(`query GetUser($id: ID!) { user(id: $id) { id name } }`, { id: "42" }) * ``` */ import type { Misina } from "../types.mjs"; export interface GraphqlOptions { /** Endpoint path appended to the misina baseURL. Default: '/graphql'. */ endpoint?: string; /** * Enable Apollo Automatic Persisted Queries. Default: false. When on, * the client sends only the SHA-256 hash; if the server replies with * `PersistedQueryNotFound`, the client retries with the full query. */ persistedQueries?: boolean; /** * Send queries as GET when the URL would stay below this many chars. * Default: 0 (disabled). Mutations always use POST. */ getFallbackBelow?: number; } export interface GraphqlClient { /** Run a query (read). May use GET fallback when configured. */ query< TData = unknown, TVars = Record >(query: string, variables?: TVars, options?: GraphqlCallOptions): Promise; /** Run a mutation (write). Always POST. */ mutate< TData = unknown, TVars = Record >(query: string, variables?: TVars, options?: GraphqlCallOptions): Promise; } export interface GraphqlCallOptions { /** Operation name to send in the request envelope. */ operationName?: string; /** Per-call extras merged onto the misina init. */ signal?: AbortSignal; headers?: Record; } export interface GraphqlError { message: string; path?: Array; extensions?: { code?: string; [key: string]: unknown; }; [key: string]: unknown; } export declare class GraphqlAggregateError extends Error { override readonly name = "GraphqlAggregateError"; readonly errors: GraphqlError[]; readonly data: unknown; constructor(errors: GraphqlError[], data: unknown); } export declare function createGraphqlClient(misina: Misina, options?: GraphqlOptions): GraphqlClient;