Git Product home page Git Product logo

Comments (7)

asinorum avatar asinorum commented on July 20, 2024 3

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.

asinorum avatar asinorum commented on July 20, 2024

hey, @ArielPenna Have you been able to solve the problem?

from classsed-graphql-mern-apollo.

ArielPenna avatar ArielPenna commented on July 20, 2024

Not yet, I can´t find what is wrong, cause actually the localstorage updates just
fine

from classsed-graphql-mern-apollo.

asinorum avatar asinorum commented on July 20, 2024

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.

ArielPenna avatar ArielPenna commented on July 20, 2024

It actually works, Thanks a lot!!!

from classsed-graphql-mern-apollo.

Panosmpero avatar Panosmpero commented on July 20, 2024

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.

SudhanshuBlaze avatar SudhanshuBlaze commented on July 20, 2024

@asinorum love you man for the fix!!

from classsed-graphql-mern-apollo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.