Skip to content

Commit

Permalink
Fix: create scripts missing import
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubcolony authored and rdig committed May 3, 2024
1 parent 050c725 commit f1940f7
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/utils/graphqlRequest.js
Original file line number Diff line number Diff line change
@@ -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,
};

0 comments on commit f1940f7

Please sign in to comment.