Skip to content

Instantly share code, notes, and snippets.

@stubailo
Created September 5, 2017 08:15
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save stubailo/8bd3b0ef9c1dcb1459bf0076e3d612af to your computer and use it in GitHub Desktop.
Save stubailo/8bd3b0ef9c1dcb1459bf0076e3d612af to your computer and use it in GitHub Desktop.
Call a GraphQL API with fetch
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));
@dio
Copy link

dio commented Jun 23, 2018

curl -s -d '{ "query": "{ posts { title } }" }' -H "Content-Type: application/json" https://1jzxrj179.lp.gql.zone/graphql

@lokeshjain2008
Copy link

👍🏼

@miriam-samuels
Copy link

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

@qnxdev
Copy link

qnxdev commented Aug 24, 2021

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