-
Notifications
You must be signed in to change notification settings - Fork 0
/
bul.js
49 lines (45 loc) · 1.16 KB
/
bul.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const API_URL = "https://bul-api-url.com/api/graphql";
const bulQuery = async ({ query, cookies, variables, apiUrl }) => {
const Cookie = cookies
? cookies
.map((cookie) => [cookie?.name, cookie?.value].join("="))
.join("; ")
: undefined;
const res = await fetch(apiUrl || API_URL, {
credentials: "include",
method: "POST",
body: JSON.stringify({
query: `${query}`,
variables,
}),
headers: {
"Content-Type": "application/json",
Cookie,
},
}).then((res) => res.json());
return res;
};
const bulMutation = async ({ query, cookies, variables, apiUrl }) => {
const Cookie = cookies
? cookies
.map((cookie) => [cookie?.name, cookie?.value].join("="))
.join("; ")
: undefined;
return await fetch(apiUrl || API_URL, {
cache: "no-cache",
credentials: "include",
method: "POST",
body: JSON.stringify({
query: `${query}`,
variables,
}),
headers: {
"Content-Type": "application/json",
Cookie,
},
}).then((res) => res.json());
};
const bulgql = (query) => {
return query.loc.source.body;
};
export { bulMutation, bulQuery, bulgql };