-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (19 loc) · 688 Bytes
/
index.js
File metadata and controls
21 lines (19 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import axios from 'axios';
const GraphQLFetch = async ({ query, variables = {} }) => {
const config = {
"Content-Type": "application/json"
};
const data = { query, variables }
const endpoint = "http://localhost:8000/api/graphql/"
return await axios({url: endpoint, data: data, headers: config, method: "POST"}).then((response) => {
if(response.statusText === 'OK' && response.headers && response.headers["content-type"] === 'application/json')
return response.data;
throw response;
}).catch((e) => {
return {
error: { code: "UNKNOWN ERROR", message: "Unknown Error - " + e.status },
response: e,
};
});
};
export default GraphQLFetch;