Last active
July 29, 2017 16:02
-
-
Save jbaxleyiii/3b9037c162eaee16b6b6c9bcb89dd243 to your computer and use it in GitHub Desktop.
Base component
This file contains hidden or 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 React from "react"; | |
import gql from "graphql-tag"; | |
import { graphql } from "react-apollo"; | |
export const HERO_QUERY = gql` | |
query GetCharacter($episode: Episode!) { | |
hero(episode: $episode) { | |
name | |
id | |
friends { | |
name | |
id | |
appearsIn | |
} | |
} | |
} | |
`; | |
export const withCharacter = graphql(HERO_QUERY, { | |
options: () => ({ | |
variables: { episode: "JEDI" }, | |
}), | |
}); | |
export default withCharacter(({ data: { loading, hero, error } }) => { | |
if (loading) return <div>Loading</div>; | |
if (error) return <h1>ERROR</h1>; | |
return ( | |
<div> | |
{hero && | |
<div> | |
<h3>{hero.name}</h3> | |
{hero.friends.map(friend => | |
<h6 key={friend.id}> | |
{friend.name}: | |
{" "}{friend.appearsIn.map(x => x.toLowerCase()).join(", ")} | |
</h6> | |
)} | |
</div>} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment