aboutsummaryrefslogtreecommitdiff
path: root/source/library/fetcher/http.ts
diff options
context:
space:
mode:
Diffstat (limited to 'source/library/fetcher/http.ts')
-rw-r--r--source/library/fetcher/http.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/library/fetcher/http.ts b/source/library/fetcher/http.ts
new file mode 100644
index 0000000..3138226
--- /dev/null
+++ b/source/library/fetcher/http.ts
@@ -0,0 +1,30 @@
+
+
+
+/*** 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();
+ };
+}