This repository has been archived on 2023-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-old/src/libs/requestCreator.js

24 lines
565 B
JavaScript

export const API_URI = 'https://api.tribalwarshelp.com/graphql';
export default ({ query, variables = {} } = {}) => {
return fetch(API_URI, {
method: 'POST',
body: JSON.stringify({
query,
variables,
}),
headers: {
'Content-Type': 'application/json',
},
})
.then(res => {
return res.json();
})
.then(({ data, errors }) => {
if (errors && Array.isArray(errors) && errors.length > 0) {
throw new Error(errors[0].message);
}
return new Promise(resolve => resolve(data));
});
};