summaryrefslogtreecommitdiffstats
path: root/frontend/enhancers
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-02-08 10:41:16 -0500
committerWes Bos <wesbos@gmail.com>2018-02-08 10:41:16 -0500
commit19c9683e2126c68cb9d231293162c756d69c51fb (patch)
tree4679ca2dee47740aa0bf6fe623513c4242e027e6 /frontend/enhancers
parenteabff7cd396d1f37ceb929e666f082ce57f07919 (diff)
WIP
Diffstat (limited to 'frontend/enhancers')
-rw-r--r--frontend/enhancers/enhancers.js36
1 files changed, 30 insertions, 6 deletions
diff --git a/frontend/enhancers/enhancers.js b/frontend/enhancers/enhancers.js
index 525c720..ff1712f 100644
--- a/frontend/enhancers/enhancers.js
+++ b/frontend/enhancers/enhancers.js
@@ -1,13 +1,37 @@
-import { ALL_ITEMS_QUERY } from "../queries/index";
-import { graphql } from "react-apollo";
+import { ALL_ITEMS_QUERY, REMOVE_ITEM_MUTATION, SINGLE_ITEM_QUERY } from '../queries/index';
+import { graphql } from 'react-apollo';
export const itemEnhancer = graphql(ALL_ITEMS_QUERY, {
- name: "allItemsQuery",
+ name: 'itemsQuery',
options({ page }) {
return {
variables: {
- skip: page * 3 - 3
- }
+ skip: page * 3 - 3,
+ },
};
- }
+ },
+});
+
+export const removeItemMutation = graphql(REMOVE_ITEM_MUTATION, {
+ name: 'removeItem',
+ options: {
+ update: (proxy, { data: { deleteItem } }) => {
+ // grab the data from our cache
+ const data = proxy.readQuery({ query: ALL_ITEMS_QUERY });
+ console.log(data);
+ // filter out the deleted item
+ data.items = data.items.filter(item => item.id !== deleteItem.id);
+
+ // and then "set state" (update cache), so it will update wherever we have used this data on the page
+ proxy.writeQuery({ query: ALL_ITEMS_QUERY, data });
+ },
+ },
+});
+
+export const singleItemEnhancer = graphql(SINGLE_ITEM_QUERY, {
+ name: 'findItem',
+ // This comes from Props
+ options: ({ id }) => ({
+ variables: { id },
+ }),
});