Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs(graphcache): remove mutative operations (#3503)

authored by

Jovi De Croock and committed by
GitHub
56c1544b 614c7326

+12 -6
+5 -4
docs/graphcache/cache-updates.md
··· 260 260 `; 261 261 262 262 cache.updateQuery({ query: TodoList }, data => { 263 - data.todos.push(result.createTodo); 264 - return data; 263 + return { 264 + ...data, 265 + todos: [...data.todos, result.createTodo], 266 + }; 265 267 }); 266 268 }, 267 269 }, ··· 299 301 createTodo(result, _args, cache, _info) { 300 302 const todos = cache.resolve('Query', 'todos'); 301 303 if (Array.isArray(todos)) { 302 - todos.push(result.createTodo); 303 - cache.link('Query', 'todos', todos); 304 + cache.link('Query', 'todos', [...todos, result.createTodo]); 304 305 } 305 306 }, 306 307 },
+7 -2
examples/with-graphcache-updates/src/client.js
··· 29 29 variables: { first: lastField.arguments.first }, 30 30 }, 31 31 data => { 32 - data.links.nodes.push(result.createLink.node); 33 - return data; 32 + return { 33 + ...data, 34 + links: { 35 + ...data.links, 36 + nodes: [...data.links.nodes, result.createLink.node], 37 + }, 38 + }; 34 39 } 35 40 ); 36 41 }