Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateQueries will not update the data node #1085

Closed
luckyyang opened this issue Dec 23, 2016 · 4 comments
Closed

updateQueries will not update the data node #1085

luckyyang opened this issue Dec 23, 2016 · 4 comments

Comments

@luckyyang
Copy link

updateQueries will not update the data node after successfully get data from graphQl
apollo-client version: 2.5.20
react-apollo version: 0.7.2

screenshots to illustrate the issue:

before create new data:
2016-12-23 6 43 08

submit the form and get result from graphQL:
2016-12-23 6 41 55

data list not update automatically:
2016-12-23 6 43 08

after refresh the page got data updated:
2016-12-23 6 43 34

attach my code:

// graphqlModule/updateQueries/providerList.js

export const providerList = {
  userList: (prev, { mutationResult }) => {
    const result = mutationResult.data.registerWithIdentification

    return update(prev, {
      userList: {
        data: {
          $unshift: [result]
        }
      }
    })
  },
}

======

// container.js

import { providerList as updateQueries } from 'graphqlModule/updateQueries/providerList'

  async submit() {
        const res = await mutate({ variables, updateQueries })
  }
@helfer
Copy link
Contributor

helfer commented Dec 25, 2016

@luckyyang Are you sure that your udpateQuery function even runs? If it runs, it most likely doesn't update because you have an error in it. I recently noticed that errors in reducers get swallowed, so it may be the same here. Make sure to check the entire update function is running, for example by putting a print statement right before the return statement.

@luckyyang
Copy link
Author

If it runs, it most likely doesn't update because you have an error in it

@helfer You mean If it NOT runs ? I don't see any errors in my code and dev tools.

for example by putting a print statement right before the return statement

I can see the mutate result has been returned, I put a breakpoint before return statement and got no error and get the update data after refresh the page.

Do you have any idea about that?

@luckyyang
Copy link
Author

luckyyang commented Dec 26, 2016

I can get error when use wrong param for update:

   return update(prev, {
      userList: {
        data: {
          $push: result
        }
      }
    })

2016-12-26 12 39 16

No error for below code(however not get data updated):

   return update(prev, {
      userList: {
        data: {
          $push:[result]
        }
      }
    })

@luckyyang
Copy link
Author

works now after I deleted all the data in database, I think It's due to the bad format of my history data. We have changed data schema for several times. close this issue

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants