From afe09dd59a9752966ef04a3bdee51cd5bfe7cfb2 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:51:28 +0200 Subject: [PATCH] Add requestGraphQlJson --- lib/request.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/request.ts b/lib/request.ts index 3cd002e..8ec8c88 100644 --- a/lib/request.ts +++ b/lib/request.ts @@ -14,3 +14,15 @@ export const requestJson = async ( const response = await fetch(endpoint, config); return response.ok ? response.json() : Promise.reject(new Error(await response.text())); }; + +type RequestGraphQlJsonConfig = Omit & { body: { query: string } }; + +/** + * The fallback URL works for classic databases,for more information about regions see: + * https://docs.fauna.com/fauna/current/learn/understanding/region_groups + */ +export const requestGraphQlJson = (config: RequestGraphQlJsonConfig) => + requestJson(process.env.FAUNADB_URL || "https://graphql.fauna.com/graphql", { + ...config, + headers: { Authorization: `Bearer ${process.env.FAUNADB_SECRET}`, ...config.headers }, + });