Skip to content

Instantly share code, notes, and snippets.

@coopermaruyama
Created July 21, 2017 05:47
Show Gist options
  • Save coopermaruyama/3cd7eb4d0f7e8d7c0ac9e178bc70a8ff to your computer and use it in GitHub Desktop.
Save coopermaruyama/3cd7eb4d0f7e8d7c0ac9e178bc70a8ff to your computer and use it in GitHub Desktop.
Simplest way to query a graphql API
const { createApolloFetch } = require('apollo-fetch');
const uri = 'http://localhost:3000/graphql';
const apolloFetch = createApolloFetch({ uri });
const query = `
query getTodos {
todos {
title
completed
}
}
`;
apolloFetch({ query })
.then(result => console.log(result.data.todos)); // Array of todos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment