Skip to content

Instantly share code, notes, and snippets.

@chemiadel
Created October 6, 2021 07:27
Show Gist options
  • Save chemiadel/909817dba60b9c7c7836d7a4a9e8da8b to your computer and use it in GitHub Desktop.
Save chemiadel/909817dba60b9c7c7836d7a4a9e8da8b to your computer and use it in GitHub Desktop.
simple-gql-fetcher
const fetcher = async (query : string, variables?: any, headers?: any ) => await fetch(`/api/graphql`, {
method:'post',
headers: {
'Content-Type': 'application/json',
...headers
},
body: JSON.stringify({
query,
variables
})
})
.then( res=> res.json())
.then( json => json.data)
export default fetcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment