react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Update store in mutation get an undefined element on top of the query

Open louishugens opened this issue 6 years ago • 0 comments

Hello guys,

I have a list of element and I try to update the cache when adding a new one. The update code in the Mutation:

update={(store, { data: { article } }) => { const first = ITEMS_PER_PAGE const skip = 0 const orderBy = 'createdAt_DESC' const data = store.readQuery({ query: ARTICLES_QUERY, variables: { first, skip, orderBy }, }) console.log('data', data) data.articles.articles.shift() console.log('data', data) data.articles.articles.unshift(article) console.log('data', data) store.writeQuery({ query: ARTICLES_QUERY, data, variables: { first, skip, orderBy }, }) }}

the query works fine in the list: data : {articles: {…}}articles: articles: Array(10)0: {id: "cjwkz1mv6002t07714dhb0sfv", nom: "papapdo", code: "p00939", prix: 2334, typename: "Article"}1: {id: "cjwkyjxt4002a07718cafquvg", nom: "papa", code: "p00", prix: 876, typename: "Article"}2: {id: "cjwkyjxn50025077181yogqtz", nom: "papa", code: "p00", prix: 876, typename: "Article" But after the Mutation fires, an undefined item is added. data: articles: articles: Array(10) 0: undefined 1: {id: "cjwkzm2xa003t0771f8mce1js", nom: "Papillon", code: "P-003", prix: 984, typename: "Article"} 2: {id: "cjwkzkkmz003o0771hjsop9i2", nom: "llsl", code: "oro", prix: 9394, typename: "Article"}

Please help.

louishugens avatar Jun 09 '19 12:06 louishugens