Created
September 19, 2021 13:09
-
-
Save devmnj/0f960ec433a2332740c0a98b5f6c9c51 to your computer and use it in GitHub Desktop.
Graphql client for React and Keystone5 CMS - using the fetch API
This file contains hidden or 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
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