getGQLAnon.js 476 B

1234567891011121314151617181920
  1. import backendURL from './backendUrl'
  2. export const getGQLAnon = (url) => (query, variables) =>
  3. fetch(url, {
  4. method: 'POST',
  5. headers: {
  6. 'Content-Type': 'application/json'
  7. },
  8. body: JSON.stringify({ query, variables }),
  9. })
  10. .then((res) => res.json())
  11. .then((data) => {
  12. if (data.data) {
  13. return Object.values(data.data)[0]
  14. } else {
  15. throw new Error(JSON.stringify(data.errors))
  16. }
  17. })
  18. export const gqlAnon = getGQLAnon(backendURL+'/graphql')