Created
March 22, 2018 18:13
-
-
Save peggyrayzis/2c72333c9ac124e6c158947007a02dc4 to your computer and use it in GitHub Desktop.
RA 2.1 mutation
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 { 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