Skip to content

Instantly share code, notes, and snippets.

@jbaxleyiii
Last active July 3, 2017 23:22
Show Gist options
  • Save jbaxleyiii/3375727c4c3f0ebb9dd68694412174d2 to your computer and use it in GitHub Desktop.
Save jbaxleyiii/3375727c4c3f0ebb9dd68694412174d2 to your computer and use it in GitHub Desktop.
Component Diff
+ // @flow
import React from "react";
import gql from "graphql-tag";
import { graphql } from "react-apollo";
+ import type { OperationComponent } from "react-apollo";
export const HERO_QUERY = gql`
query GetCharacter($episode: Episode!) {
hero(episode: $episode) {
name
id
friends {
name
id
appearsIn
}
}
}
`;
+ export type Hero = {
+ name: string,
+ id: string,
+ appearsIn: string[],
+ friends: Hero[],
+ };
+ export type Response = {
+ hero: Hero,
+ };
+ export const withCharacter: OperationComponent<Response> = graphql(HERO_QUERY, {
- export const withCharacter(({ data: { loading, hero, error } }) => {
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>
);
}
@newswim
Copy link

newswim commented Jul 3, 2017

I think line 34, where you're showing the code to be replaced, should be:

export const withCharacter = graphql(HERO_QUERY, {

34 and 40 are identical. Just caught this ~~~ (thanks for the great article!!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment