Created
January 19, 2024 23:17
-
-
Save james2doyle/28536e3de8794b94813c471950276558 to your computer and use it in GitHub Desktop.
An example of using fetch for graphql endpoints
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
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