Created
June 13, 2018 16:15
-
-
Save JakeDawkins/4be62c5147caf3ad16b9da6eee133bf7 to your computer and use it in GitHub Desktop.
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
| import React from 'react'; | |
| import gql from 'graphql-tag'; | |
| import { Query } from 'react-apollo'; | |
| // Make sure the query is also exported -- not just the component | |
| export const GET_DOG_QUERY = gql` | |
| query getDog($name: String) { | |
| dog(name: $name) { | |
| id | |
| name | |
| breed | |
| } | |
| } | |
| `; | |
| export const Dog = ({ name }) => ( | |
| <Query query={GET_DOG_QUERY} variables={{ name }}> | |
| {({ loading, error, data }) => { | |
| if (loading) return 'Loading...'; | |
| if (error) return `Error!`; | |
| return ( | |
| <p> | |
| {data.dog.name} is a {data.dog.breed} | |
| </p> | |
| ); | |
| }} | |
| </Query> | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment