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

Paginated read functions is not returning updated args when using fetchMore #11737

Open
cesarve77 opened this issue Mar 28, 2024 · 1 comment
Labels

Comments

@cesarve77
Copy link

cesarve77 commented Mar 28, 2024

Issue Description

I am using fetchMore to make pagination works.

typePolicies: {
            Query: {
                fields: {
                    books: {
                        read(existing, {args: {skip = 0}}) {
                            //THIS ARGS IS ALWAYS THE INITIAL ARGS, NEVER IS UPDATED BY FETHMORE
                            console.log('read skip', skip)
                            return existing?.slice(skip, skip + 10);
                        },
                        keyArgs: false,
                        merge(existing, incoming, {args: {skip = 0}}) {
                            //THIS IS UPDATED OK
                            console.log('merge skip', skip)
                            const merged = existing ? existing.slice(0) : [];
                            for (let i = 0; i < incoming.length; ++i) {
                                merged[skip + i] = incoming[i];
                            }
                            return merged;
                        },
                    }
                }
            }
        }
fetchMore({
    variables:{skip: skip + 10}
})

no matter what the passed to fetchMore, in read->args skip always is the initial value. while in merge->args is updated.

Link to Reproduction

https://github.com/cesarve77/apollo3bug

Reproduction Steps

git clone https://github.com/cesarve77/apollo3bug
cd apollo3bug
apollo3bug server
npm i
node index.js
cd apollo3bug
apollo3bug browser
npm i
npm run start

click on next page, check the console,
('read skip', skip) should change any timt next page is clicked

@apollo/client version

3.9.9

@jerelmiller
Copy link
Member

Hey @cesarve77 👋

Thanks for the report! We'll do our best to take a look at this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants