diff options
Diffstat (limited to 'frontend/lib/withData.js')
| -rw-r--r-- | frontend/lib/withData.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/frontend/lib/withData.js b/frontend/lib/withData.js index c823e62..93a0db1 100644 --- a/frontend/lib/withData.js +++ b/frontend/lib/withData.js @@ -1,6 +1,6 @@ import withApollo from 'next-with-apollo'; import ApolloClient from 'apollo-boost'; - +import { LOCAL_STATE_QUERY } from '../queries/index'; // can also be a function that accepts a `headers` object (SSR only) and returns a config const client = new ApolloClient({ @@ -16,6 +16,21 @@ const client = new ApolloClient({ }); } }, + clientState: { + resolvers: { + Mutation: { + toggleCart(_, variables, { cache }) { + const { cartOpen } = cache.read({ query: LOCAL_STATE_QUERY }); + const data = { data: { cartOpen: !cartOpen } }; + cache.writeData(data); + return data; + }, + }, + }, + defaults: { + cartOpen: false, + }, + }, }); export { client }; |
