phpsmarter
2/20/2018 - 2:10 AM

Query-components

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>
  );
}