Created
December 27, 2020 11:27
-
-
Save yann-yinn/abc8c3c507e07050ef7134bd72f15fae to your computer and use it in GitHub Desktop.
Create GraphQL Request with fetch
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
async function graphql({ query, variables }) { | |
let response = await fetch(process.env.FIREBLOG_GRAPHQL_ENDPOINT, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
Accept: "application/json", | |
}, | |
body: JSON.stringify({ | |
query, | |
variables, | |
}), | |
}); | |
response = await response.json(); | |
if (response.errors) { | |
console.log("❌ GraphQL Error: ", response.errors); | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment