1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17import { event } from '.';
export const graphqlQuery = async ({ query, variables = {} }) => {
const Authorization = event?.headers?.authorization;
const response = (await (await fetch(`https://graphqlv2.${process.env.URL}/v1/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...Authorization ? { Authorization } : { 'x-hasura-admin-secret': process.env.DB_PASSWORD },
},
body: JSON.stringify({ query, variables }),
})).json());
if (!response?.data) {
console.log(JSON.stringify({ graphqlError: response }));
}
return response?.data;
}