Skip to content

Instantly share code, notes, and snippets.

@woss
Forked from stubailo/apollo-fetch.js
Created September 17, 2018 16:32
Show Gist options
  • Save woss/b8439d4eb149eab3ff59430b21d89cd6 to your computer and use it in GitHub Desktop.
Save woss/b8439d4eb149eab3ff59430b21d89cd6 to your computer and use it in GitHub Desktop.
Call a GraphQL API with apollo-fetch
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);
});
@sidikif
Copy link

sidikif commented Sep 17, 2018

it's very usefull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment