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

Please don't remove updateQuery. #8915

Closed
j3pic opened this issue Oct 12, 2021 · 5 comments · Fixed by #9504
Closed

Please don't remove updateQuery. #8915

j3pic opened this issue Oct 12, 2021 · 5 comments · Fixed by #9504

Comments

@j3pic
Copy link

j3pic commented Oct 12, 2021

I'm just learning how to use this client by working on an existing app that uses it.

While building a new react-hoc component, I ran into this:

The updateQuery callback for fetchMore is deprecated, and will be removed
in the next major version of Apollo Client.

Please convert updateQuery functions to field policies with appropriate
read and merge functions, or use/adapt a helper function (such as
concatPagination, offsetLimitPagination, or relayStylePagination) from
@apollo/client/utilities.

The field policy system handles pagination more effectively than a
hand-written updateQuery function, and you only need to define the policy
once, rather than every time you call fetchMore.

I've never heard of "field policies", and this software is already complicated enough as it is.
I took a quick look at StackOverflow, only to learn that I'll also have to figure out how to integrate some cache mechanism into my code. The SO answer only shows how to create the cache, not what to do with it.

I don't really want to go down the field-policy rabbit hole. I just want to be able to update the data with a new query. I'm not using fetchMore strictly to implement pagination. I notice that with updateQuery, fetchMore is perfectly sufficient to allow implementation of a filter function. I've figured this out the hard way, since the documentation is written as if pagination is the only thing you'd ever want to do with fetchMore.

And then there appear to be bugs associated with the read and merge functions. I just don't want to deal with it. Please allow working code to continue working.

@d4rky-pl
Copy link

The field policy system handles pagination .more effectively than a
hand-written updateQuery function, and you only need to define the policy
once, rather than every time you call fetchMore.

The whole point of hand-written updateQuery function is that I only want to define the policy once, in a specific component, for a specific use-case, not for the entire application and every single place I am able to use given query. I use fetchMore to implement infinite scrolling which is really cumbersome in Apollo as it is and if I'm being forced to also write field policies and then explain to other developers how all of it is supposed to work, I may just as well switch to another library altogether.

@dylanwulf
Copy link
Contributor

@d4rky-pl sorry I don't have any solutions to your problem, but if you want you could mention your problems in the new feedback survey: #9732

@benjamn
Copy link
Member

benjamn commented May 20, 2022

Good news (I hope) @j3pic @d4rky-pl @dylanwulf: we removed the deprecation warning for updateQuery in Apollo Client v3.6.0, in commit 1b3406a as part of PR #9504.

This means we will not be removing updateQuery support, and are in fact leaning into it by providing cache.updateQuery and cache.updateFragment methods (#8382), in terms of which I was able to reimplement fetchMore's updateQuery function.

Threatening to deprecate updateQuery has done all the good it can do, in terms of getting folks to try InMemoryCache field policies instead, and now it's just annoying developers who may have good reasons for not switching to a centralized field policy.

My only advice for using updateQuery "safely" is to define a field policy with at least keyArgs: false for any paginated field you plan to manage using updateQuery and fetchMore, so the field arguments (offset, limit, cursor, etc) do not end up fragmenting the field's data unnecessarily in the cache, allowing you to work with one big array within updateQuery (simpler in most cases). More about keyArgs.

Long story short: you should no longer see the fetchMore updateQuery deprecation warning if you update to v3.6.x with npm i @apollo/client@latest.

@jerelmiller
Copy link
Member

Hey all 👋

I know its been some time since the last update, but I wanted to draw attention to #11974 which fixes an issue with fetchMore and no-cache queries. This PR addresses some compatibility issues with these together by enforcing the use of updateQuery to perform the result merging in order for the client to update the query value.

As such, we are solidifying the use of updateQuery and making it a necessary part of the fetchMore API which means no risk of deprecating this API again anytime soon.

Since this issue is now almost 3 years old, I'm going to close it out since the warning that originally prompted this issue has been removed and we don't plan to to deprecate this again anytime in the near future. Thanks!

Copy link
Contributor

github-actions bot commented Aug 1, 2024

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