Skip to content

Instantly share code, notes, and snippets.

@JakeDawkins
Created June 13, 2018 16:15
Show Gist options
  • Select an option

  • Save JakeDawkins/4be62c5147caf3ad16b9da6eee133bf7 to your computer and use it in GitHub Desktop.

Select an option

Save JakeDawkins/4be62c5147caf3ad16b9da6eee133bf7 to your computer and use it in GitHub Desktop.
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