Created
September 5, 2017 08:15
Call a GraphQL API with fetch
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
require('isomorphic-fetch'); | |
fetch('https://1jzxrj179.lp.gql.zone/graphql', { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify({ query: '{ posts { title } }' }), | |
}) | |
.then(res => res.json()) | |
.then(res => console.log(res.data)); |
Hi, so I already fetched the data
now I want to display the data fetched in my frontend.
How do I do that, thanks in advance
const promise = await fetch('....'); // fetch code here. don't forget to add await
res.send(await promise.json()); // res is your response object
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, so I already fetched the data
now I want to display the data fetched in my frontend.
How do I do that, thanks in advance