Created
July 21, 2017 05:47
-
-
Save coopermaruyama/3cd7eb4d0f7e8d7c0ac9e178bc70a8ff to your computer and use it in GitHub Desktop.
Simplest way to query a graphql API
This file contains hidden or 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 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