summaryrefslogtreecommitdiffstats
path: root/frontend/lib
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-04-06 16:44:50 -0400
committerWes Bos <wesbos@gmail.com>2018-04-06 16:44:50 -0400
commitd22616d5a675f5a381c741784333151255713b45 (patch)
tree51dc4a138fc4b1e8ac1b1e287e5c246f24377242 /frontend/lib
parentd90d97337c39e1fa723ee01627fbd3f78adfcf31 (diff)
local data with apollo
Diffstat (limited to 'frontend/lib')
-rw-r--r--frontend/lib/withData.js17
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 };