Created
June 3, 2018 01:09
-
-
Save larkintuckerllc/369e94da4c7b96233340605175c99e8e to your computer and use it in GitHub Desktop.
GraphQL and Apollo Client by Example: Part 3 - 2
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 gql from 'graphql-tag'; | |
| const query = gql` | |
| { | |
| counter @client | |
| } | |
| `; | |
| export default { | |
| Mutation: { | |
| decrementCounter: (_, params, { cache }) => { | |
| const { counter } = cache.readQuery({ query }); | |
| const nextCounter = counter - 1; | |
| const data = { | |
| counter: nextCounter, | |
| }; | |
| cache.writeData({ data }); | |
| return nextCounter; | |
| }, | |
| incrementCounter: (_, params, { cache }) => { | |
| const { counter } = cache.readQuery({ query }); | |
| const nextCounter = counter + 1; | |
| const data = { | |
| counter: nextCounter, | |
| }; | |
| cache.writeData({ data }); | |
| return nextCounter; | |
| }, | |
| }, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment