Skip to content

Instantly share code, notes, and snippets.

@devmnj
Created September 19, 2021 13:09
Show Gist options
  • Save devmnj/0f960ec433a2332740c0a98b5f6c9c51 to your computer and use it in GitHub Desktop.
Save devmnj/0f960ec433a2332740c0a98b5f6c9c51 to your computer and use it in GitHub Desktop.
Graphql client for React and Keystone5 CMS - using the fetch API
function gqlClient(query, variables = {}) {
return fetch("http://localhost:3000/admin/api", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
variables,
query,
}),
}).then(function (result) {
return result.json();
}).catch(err=>{
console.log('got some error');
console.log(err);
});
}
export default gqlClient;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment