Created
March 1, 2020 20:38
-
-
Save fernandodof/1833814609afaea130fd0a2208ceeb56 to your computer and use it in GitHub Desktop.
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
async function graphqlRequest(query, variables = {}) { | |
const request = { | |
method: 'POST', | |
headers: { 'content-type': 'application/json' }, | |
body: JSON.stringify({ query, variables }) | |
}; | |
const response = await fetch('http://localhost:3000/graphql', request); | |
const responseBody = await response.json(); | |
return responseBody.data; | |
}; | |
async function getUser() { | |
const query = ` | |
query UserQuery($id: ID!) { | |
user(id: $id) { | |
name | |
} | |
} | |
`; | |
const variables = { id: 1 }; | |
const data = await graphqlRequest(query, variables); | |
console.log(data.user); | |
return data.user; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment