From f1940f774d94da05e8c68817100628350152518f Mon Sep 17 00:00:00 2001 From: Jakub Zajac Date: Wed, 24 Apr 2024 00:16:23 +0100 Subject: [PATCH] Fix: create scripts missing import --- scripts/utils/graphqlRequest.js | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 scripts/utils/graphqlRequest.js diff --git a/scripts/utils/graphqlRequest.js b/scripts/utils/graphqlRequest.js new file mode 100644 index 00000000000..c8f324cc263 --- /dev/null +++ b/scripts/utils/graphqlRequest.js @@ -0,0 +1,34 @@ +const fetch = require('cross-fetch'); + +const graphqlRequest = async (queryOrMutation, variables, url, authKey) => { + const options = { + method: 'POST', + headers: { + 'x-api-key': authKey, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + query: queryOrMutation, + variables, + }), + }; + + let body; + let response; + + try { + response = await fetch(url, options); + body = await response.json(); + return body; + } catch (error) { + /* + * Something went wrong... obviously + */ + console.error(error); + return null; + } +}; + +module.exports = { + graphqlRequest, +};