Last active
June 9, 2021 11:37
-
-
Save sayon-bitquery/edcf5680e61a39a06df1ff746b549392 to your computer and use it in GitHub Desktop.
Next step, is to make a variable which would take a GraphQL query and execute it in Bitquery’s API through the endpoint.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function App() { | |
const { data, isLoading, error } = useQuery("bitcoin", () => { //launches | |
return fetch(endpoint, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
"X-API-KEY": "YOUR API KEY" | |
}, | |
body: JSON.stringify({ query: QUERY }) // ({ QUERY }) | |
}) | |
.then((response) => { | |
if (response.status >= 400) { | |
throw new Error("Error fetching data"); | |
} else { | |
return response.json(); | |
} | |
}) | |
.then((data) => data.data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment