Skip to content

Instantly share code, notes, and snippets.

@phpsmarter
Created February 20, 2018 02:10
Show Gist options
  • Save phpsmarter/543c8e3255bd33f474dc2e09cc51ec7b to your computer and use it in GitHub Desktop.
Save phpsmarter/543c8e3255bd33f474dc2e09cc51ec7b to your computer and use it in GitHub Desktop.
query components
import gql from 'graphql-tag';
import { Query } from 'react-apollo';
const query = gql`
query SomeQuery {
foo {
bar
baz
}
}
`;
function MyComponent() {
return (
<Query query={query}>
{(result) => {
if (result.loading) return <Loading />;
if (result.error) return <Error error={error} />;
const { data } = result;
return <h1>Hello {data.foo.bar} {data.foo.baz}!</h1>;
})
</Query>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment