gql.js 631 B

12345678910111213141516171819
  1. const getGQL = url =>
  2. (query, variables) => fetch(url, {
  3. method: 'POST',
  4. headers: {
  5. "Content-Type": "application/json",
  6. // 'Accept' : 'application/json',
  7. ...(localStorage.authToken ? {"Authorization": "Bearer " + localStorage.authToken} : {})
  8. },
  9. body: JSON.stringify({query, variables})
  10. }).then(res => res.json())
  11. .then(data => {
  12. if (data.data){
  13. return Object.values(data.data)[0]
  14. }
  15. else throw new Error(JSON.stringify(data.errors))
  16. })
  17. export const backendURL = 'http://chat.ed.asmer.org.ua';
  18. export const gql = getGQL(backendURL + '/graphql');