import fetch from 'unfetch'

const getStats = () => {
  const query = `
      query Stats {
        commits
        tweets
        places
        steps
        sleep
        songs
        album {
          name
          artist
        }
        books {
          name
          author
        }
      }
  `

  return fetch('https://stats.lowmess.com/graphql', {
    method: 'POST',
    body: JSON.stringify({ query }),
    headers: {
      'Content-Type': 'application/json',
    },
  })
    .then(response => {
      if (!response.ok) {
        throw new Error(`${response.status}: ${response.statusText}`)
      }

      return response.json()
    })
    .then(json => json.data)
    .catch(error => {
      console.error(error)
    })
}

export default getStats

@@ -38,16 +38,22 @@
 tStats =
+ async
  () =%3E %7B
@@ -310,22 +310,38 @@
 %0A  %60%0A%0A  
-return
+const response = await
  fetch('
@@ -508,36 +508,9 @@
  %7D)%0A
-    .then(response =%3E %7B%0A    
+%0A
   if
@@ -535,23 +535,17 @@
     
-    throw new E
+console.e
 rror
@@ -599,133 +599,81 @@
     
-  %7D%0A%0A      return response.json()%0A    %7D)%0A    .then(json =%3E json.data)%0A    .catch(error =%3E %7B%0A      console.error(error
+return false%0A  %7D%0A%0A  const %7B data %7D = await response.json(
 )%0A
+%0A
   
-  %7D)
+return data
 %0A%7D%0A%0A

use async function to fetch stats