Comments (7)
I still don't understand the problem well, but it seems quite common, for some reason Apollo doesn't notice the change.
I have found this solution (not mine), in case it helps someone:
const [createPost, {error}] = useMutation (CREATE_POST_MUTATION, { variables: values, update (proxy, result) { const data = proxy.readQuery ({ query: FETCH_POSTS_QUERY, variables: values }); data.getPosts = [result.data.createPost, ... data.getPosts]; proxy.writeQuery ({query: FETCH_POSTS_QUERY, variables: values, data}); values.body = ''; } });
from classsed-graphql-mern-apollo.
hey, @ArielPenna Have you been able to solve the problem?
from classsed-graphql-mern-apollo.
Not yet, I can´t find what is wrong, cause actually the localstorage updates just
fine
from classsed-graphql-mern-apollo.
Same here, it doesn't give me any error to work with. Everything works fine it just doesn't reload the page.
from classsed-graphql-mern-apollo.
It actually works, Thanks a lot!!!
from classsed-graphql-mern-apollo.
I still don't understand the problem well, but it seems quite common, for some reason Apollo doesn't notice the change.
I have found this solution (not mine), in case it helps someone:
const [createPost, {error}] = useMutation (CREATE_POST_MUTATION, { variables: values, update (proxy, result) { const data = proxy.readQuery ({ query: FETCH_POSTS_QUERY, variables: values }); data.getPosts = [result.data.createPost, ... data.getPosts]; proxy.writeQuery ({query: FETCH_POSTS_QUERY, variables: values, data}); values.body = ''; } });
Had same issue when deleting a post, fixed it by doing your method, adding variables to readQuery and writeQuery
const [deletePostOrComment] = useMutation(targetMutation, { variables: { postId, commentId, }, update(proxy) { setConfirmOpen(false); if (!commentId) { const data = proxy.readQuery({ query: FETCH_POSTS_QUERY, variables: { postId, commentId } }); data.getPosts = data.getPosts.filter((post) => post.id !== postId); proxy.writeQuery({ query: FETCH_POSTS_QUERY, variables: { postId, commentId }, data, }); } if (callback) callback(); }, onError(error) { console.log(error); }, });
from classsed-graphql-mern-apollo.
@asinorum love you man for the fix!!
from classsed-graphql-mern-apollo.
Related Issues (20)
- Uncaught (in promise) TypeError: Cannot read property 'extensions' of undefined
- Server deployment error
- TypeError: Cannot read property 'getPosts' of undefined HOT 3
- "Cannot read property 'unshift' of undefined" HOT 1
- args not defined. HOT 1
- Args not defined HOT 1
- Single Post Type Error HOT 4
- args not defined for react class 6 adding posts HOT 1
- Tab highlight issue HOT 1
- TypeError: Cannot read property 'username' of null
- Making what you instructed in the video but still empty getPosts HOT 2
- Getting error on register form "Cannot read property 'username' of undefined. HOT 2
- deleteComment Mutation Bug
- Unable to get Single Post in graphql server
- TypeError: Cannot convert undefined or null to object HOT 3
- Error in Import semantic-ui-css
- Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
- useMutation response changes after reloading HOT 1
- Solving: Cast to ObjectId failed for value "" at path "_id" Error
- Invalid/Expired token
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from classsed-graphql-mern-apollo.