/*** UTILITY ------------------------------------------ ***/ import type { Fetcher, FetcherOptions } from "./types.ts"; /*** EXPORT ------------------------------------------- ***/ export function createHttpFetcher(options: FetcherOptions): Fetcher { const fetchImpl = options.fetch ?? globalThis.fetch; return async (req) => { const response = await fetchImpl(options.url, { body: JSON.stringify({ operationName: req.operationName, query: req.query, variables: req.variables }), headers: { "Content-Type": "application/json", ...options.headers, ...req.headers }, method: "POST" }); return await response.json(); }; }