Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created January 19, 2024 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/28536e3de8794b94813c471950276558 to your computer and use it in GitHub Desktop.
Save james2doyle/28536e3de8794b94813c471950276558 to your computer and use it in GitHub Desktop.
An example of using fetch for graphql endpoints
fetch('/graphql', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${storefrontToken}`
},
body: JSON.stringify({
query: gqlQueryString
})
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.error(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment