Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created June 3, 2018 01:09
Show Gist options
  • Save larkintuckerllc/369e94da4c7b96233340605175c99e8e to your computer and use it in GitHub Desktop.
Save larkintuckerllc/369e94da4c7b96233340605175c99e8e to your computer and use it in GitHub Desktop.
GraphQL and Apollo Client by Example: Part 3 - 2
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