Skip to content

Instantly share code, notes, and snippets.

@jbaxleyiii
Last active August 16, 2016 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbaxleyiii/1a99254d8966646c67aae038692da757 to your computer and use it in GitHub Desktop.
Save jbaxleyiii/1a99254d8966646c67aae038692da757 to your computer and use it in GitHub Desktop.
//components/TodoApp.js
import { graphql } from 'react-apollo'
class TodoApp extends React.Component {
render () { ... }
}
const withTodos = graphql(todosQuery, {
 props({ loading, data }) {
    return { todos: data ? data.todos : [] };
 }
});
const withAddTodo = graphql(addTodoMutation, {
 props: ({ mutate })  => ({
   addTodo: (text) => mutate({ variables: { text } });
 })
});
const withToggleTodo = graphql(toggleTodoMutation, {
 props: ({ mutate })  => ({
   toggleTodo: (id, complete) => mutate({ variables: { id, complete } });
 })
});
export default withTodos(withAddTodo(withToggleTodo(TodoApp)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment