-
-
Save Developerayo/584d2a56d40cdce437c3253fb4906c5e to your computer and use it in GitHub Desktop.
This file contains 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 { adopt } from 'react-adopt'; | |
import { gql } from 'apollo-boost'; | |
const INCREASE_COUNT = gql` | |
mutation increaseCount { | |
increaseCount { | |
id | |
currentCount | |
timestamp | |
} | |
} | |
`; | |
const UPDATE_TIMESTAMP = gql` | |
mutation updateTimestamp { | |
updateTimestamp { | |
id | |
currentCount | |
timestamp | |
} | |
} | |
`; | |
const increaseCount = ({ render }) => ( | |
<Mutation mutation={INCREASE_COUNT}> | |
{(mutation, result) => render({ mutation, result })} | |
</Mutation> | |
); | |
const updateTimestamp = ({ render }) => ( | |
<Mutation mutation={UPDATE_TIMESTAMP}> | |
{(mutation, result) => render({ mutation, result })} | |
</Mutation> | |
) | |
const Composed = adopt({ | |
increaseCount, | |
updateTimestamp, | |
}); | |
export const IncreaseCountButton = () => ( | |
<Composed> | |
{(mutations) => { | |
return ( | |
<button | |
type="button" | |
onClick={() => { | |
mutations.increaseCount.mutation(); | |
mutations.updateTimestamp.mutation(); | |
}} | |
> | |
Increase count | |
</button> | |
); | |
}} | |
</Composed> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment