For example how I can do that using XMLHttpRequest?
Query and serverUrl are below:
const serverUrl = 'http://example.com/graphql/'
const query = {
query: `{
viewer {
date
}
}`
};
POST request with 'Content-Type', 'application/json'const yourServerUrl = 'http://example.com/graphql'
const yourQuery = {
query: `{
users {
firstName
}
}`
};
// below ordinary XHR request with console.log
const xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.open('POST', yourServerUrl);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function () {
console.log('data returned:', xhr.response);
};
xhr.send(JSON.stringify(yourQuery));
source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With