Skip to content

Instantly share code, notes, and snippets.

@peggyrayzis
Created March 22, 2018 18:13
Show Gist options
  • Save peggyrayzis/2c72333c9ac124e6c158947007a02dc4 to your computer and use it in GitHub Desktop.
Save peggyrayzis/2c72333c9ac124e6c158947007a02dc4 to your computer and use it in GitHub Desktop.
RA 2.1 mutation
import React from "react";
import { Mutation } from "react-apollo";
import gql from "graphql-tag";
const TOGGLE_TODO = gql`
mutation ToggleTodo($id: Int!) {
toggleTodo(id: $id) {
id
completed
}
}
`;
const Todo = ({ id, text }) => (
<Mutation mutation={TOGGLE_TODO} variables={{ id }}>
{(toggleTodo, { loading, error, data }) => (
<div>
<p onClick={toggleTodo}>
{text}
</p>
{loading && <p>Loading...</p>}
{error && <p>Error :( Please try again</p>}
</div>
)}
</Mutation>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment