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

You must provide an updateQuery function when using fetchMore with a no-cache fetch policy. #12253

Closed
username14415 opened this issue Jan 7, 2025 · 4 comments

Comments

@username14415
Copy link

Issue Description

Why useQuery with no-cache requires updateQuery?
I get You must provide an updateQuery function when using fetchMore with a no-cache fetch policy. using this code:

  const { loading, fetchMore } = useQuery(GET_MESSAGES_QUERY, { variables: { messenger_chat_id: 1 }, fetchPolicy: "no-cache", onCompleted: handleCompleted, onError: handleError });

    const fetch = await fetchMore({
      variables: {
        before: 200,
      },
    });
 

Link to Reproduction

Reproduction Steps

No response

@apollo/client version

3.12.4

Copy link

triagster bot commented Jan 7, 2025

Related issues:

Was this useful? Use the thumbs up or thumbs down reaction to give feedback.

@jerelmiller
Copy link
Member

Hey @username14415 👋

Please see this this section of the docs which explains the error more in-depth.

tl;dr; because no-cache doesn't write to the cache, we don't know how you want to merge the results from the paginated response returned from fetchMore with your existing response. Some might want to do a full replacement. Others might want it stored in a single list. We require updateQuery for this reason.

@jerelmiller
Copy link
Member

I'm going to go ahead and close this, but feel free to respond if you have more questions. Thanks!

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

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

No branches or pull requests

2 participants