Created
December 17, 2018 23:36
-
-
Save adrianhall/4b75020c793a0489b93d90a48c471ab9 to your computer and use it in GitHub Desktop.
This file contains 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 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