apollo icon indicating copy to clipboard operation
apollo copied to clipboard

fetchMore duplicating new results instead of merging with previousResult

Open EdnaldoNeimeg opened this issue 7 years ago • 2 comments

Version 3.0.0-beta.25 I'm trying to fetchMore results from server, howerver, the new records are duplicated.

I have a list: A,B,C I'm using fetchMore to load D,E,F. The server response is ok, but vue-apollo gives me D,E,F,D,E,F

Here's the techMore method:

    `show_more_comments(){
        if(this.fetched){
            this.$set( this,'page', this.page + 1 )
            this.$apollo.queries.comments.fetchMore({
                variables:{
                    page:this.page,
                    limit:this.limit,
                    post_id:this.post.id
                },
                updateQuery: (previousResult, {fetchMoreResult}) => {
                    const newComments = fetchMoreResult.comments.data
                    return {
                        comments: {
                            __typename: previousResult.comments.__typename,
                            data: [...previousResult.comments.data, ...newComments]
                        }
                    }
                }
            })
        } else {
            this.triggerCommentsQuery()
        }
    }`

EdnaldoNeimeg avatar Dec 03 '18 19:12 EdnaldoNeimeg

~~I'm getting this too, even when just copy-pasting the documentation.~~

query.fetchMore({
  variables,
  updateQuery: (
    previous: ListViewQuery,
    { fetchMoreResult: result },
  ): ListViewQuery => {
    return {
      ListEntries: [...previous.ListEntries, ...result.ListEntries],
    }
  },
})

Nevermind, it was fetching the wrong pages in fetchMore

beeequeue avatar Sep 14 '19 22:09 beeequeue

@EdnaldoNeimeg Could you please provide a runnable reproduction? Thanks!

Akryum avatar Oct 21 '19 09:10 Akryum