Last active
November 22, 2018 13:30
-
-
Save barsumek/c1d20e7487696e99dd37ec243f075dc2 to your computer and use it in GitHub Desktop.
Detox your GraphQL: Pokemon Screen
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
class PokemonScreen extends Component { | |
render() { | |
const { loading, error, myPokemon } = this.props.data; | |
if (loading) { | |
return <ActivityIndicator /> | |
} | |
if (error) { | |
return <ErrorScreen /> | |
} | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.text}>Your favourite Pokemon:</Text> | |
<Text style={styles.text}>{`Name: ${myPokemon.name}`}</Text> | |
<Text style={styles.text}>{`Level: ${myPokemon.level === 30 ? 'MaxLvl' : myPokemon.level}`}</Text> | |
<Text style={styles.text}>{`Type: ${myPokemon.type}`}</Text> | |
<Text style={styles.text}>{`Caught: ${new Date(myPokemon.catchDate).toUTCString()}`}</Text> | |
</View> | |
); | |
} | |
} | |
export default graphql(gql` | |
query PokemonQuery { | |
myPokemon { | |
id | |
name | |
type | |
level | |
catchDate | |
} | |
} | |
`)(PokemonScreen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment