Skip to content

Instantly share code, notes, and snippets.

@yann-yinn
Created December 27, 2020 11:27
Show Gist options
  • Save yann-yinn/abc8c3c507e07050ef7134bd72f15fae to your computer and use it in GitHub Desktop.
Save yann-yinn/abc8c3c507e07050ef7134bd72f15fae to your computer and use it in GitHub Desktop.
Create GraphQL Request with fetch
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