aboutsummaryrefslogtreecommitdiff
path: root/source/library/fetcher/http.ts
blob: 64322f21d7b07befbdb51f304cc2de6518c69691 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*** UTILITY ------------------------------------------ ***/

import { buildHeaders, postJson } from "./http-body.ts";
import type { Fetcher, FetcherOptions } from "./types.ts";

/*** EXPORT ------------------------------------------- ***/

export function createHttpFetcher(options: FetcherOptions): Fetcher {
  const fetchImpl = options.fetch ?? globalThis.fetch;

  return async (req) => {
    return await postJson(fetchImpl, options.url, buildHeaders(options, req), {
      operationName: req.operationName,
      query: req.query,
      variables: req.variables
    });
  };
}