-
-
Save woss/b8439d4eb149eab3ff59430b21d89cd6 to your computer and use it in GitHub Desktop.
Call a GraphQL API with apollo-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
const { createApolloFetch } = require('apollo-fetch'); | |
const fetch = createApolloFetch({ | |
uri: 'https://1jzxrj179.lp.gql.zone/graphql', | |
}); | |
fetch({ | |
query: '{ posts { title }}', | |
}).then(res => { | |
console.log(res.data); | |
}); | |
// You can also easily pass variables for dynamic arguments | |
fetch({ | |
query: `query PostsForAuthor($id: Int!) { | |
author(id: $id) { | |
firstName | |
posts { | |
title | |
votes | |
} | |
} | |
}`, | |
variables: { id: 1 }, | |
}).then(res => { | |
console.log(res.data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's very usefull