Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created December 17, 2018 23:36
Show Gist options
  • Save adrianhall/4b75020c793a0489b93d90a48c471ab9 to your computer and use it in GitHub Desktop.
Save adrianhall/4b75020c793a0489b93d90a48c471ab9 to your computer and use it in GitHub Desktop.
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
import * as React from 'react';
import UserBlockComponent from '../components/UserBlock';
const query = gql`
query me {
me { id name }
}
`;
class UserBlock extends React.Component {
render() {
if (this.props.loading) {
return (<LoadingIndicator/>):
} else if (props.errors) {
return (<ErrorIndicator errors={this.props.errors}/>);
} else {
return (<UserBlockComponent name={this.props.name}/>);
}
}
}
export default graphql(query, {
options: {
fetchPolicy: 'cache-and-network'
},
props: props => ({
loading: props.loading,
errors: props.errors,
name: props.data.me.name || 'undefined'
})
})(UserBlock);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment