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

Remove setOptions and tweak reobserve #12463

Merged
merged 23 commits into from
Mar 24, 2025
Merged

Conversation

jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Mar 19, 2025

Closes #12447

Make reobserve a public, documented API in ObservableQuery. Removes setOptions as this was pretty much an alias for reobserve without the networkStatus option.

This PR also makes setting the networkStatus in a private way. We didn't like that reobserve let you set whatever you wanted if this was made public, so that argument has been removed. There is now a private way to set this value inside ObservableQuery for the internal functions.

@jerelmiller jerelmiller requested a review from phryneas March 19, 2025 23:15
Copy link

changeset-bot bot commented Mar 19, 2025

🦋 Changeset detected

Latest commit: f15b031

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svc-apollo-docs
Copy link

svc-apollo-docs commented Mar 19, 2025

⚠️ Docs preview not attached to branch

The preview was not built because the PR's base branch release-4.0 is not in the list of sources.

An Apollo team member can comment one of the following commands to dictate which branch to attach the preview to:

  • !docs set-base-branch version-2.6
  • !docs set-base-branch main

Build ID: 2f41a13d53e820e738af2532

Copy link

pkg-pr-new bot commented Mar 19, 2025

npm i https://pkg.pr.new/@apollo/client@12463

commit: f15b031

Copy link

netlify bot commented Mar 19, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit f15b031
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67e1afce8c071900085416fa
😎 Deploy Preview https://deploy-preview-12463--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Mar 19, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 41.26 KB (+0.36% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 36.66 KB (-0.04% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 31.86 KB (+0.2% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.84 KB (+0.01% 🔺)
import { ApolloProvider } from "@apollo/client/react" 5.17 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 960 B (0%)
import { useQuery } from "@apollo/client/react" 7.22 KB (-0.1% 🔽)
import { useQuery } from "@apollo/client/react" (production) 3 KB (-0.23% 🔽)
import { useLazyQuery } from "@apollo/client/react" 6.39 KB (+0.1% 🔺)
import { useLazyQuery } from "@apollo/client/react" (production) 2.17 KB (+0.05% 🔺)
import { useMutation } from "@apollo/client/react" 6.46 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 2.23 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.83 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 2.62 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.18 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.97 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.02 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.81 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.06 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.87 KB (0%)
import { useReadQuery } from "@apollo/client/react" 5.82 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.58 KB (0%)
import { useFragment } from "@apollo/client/react" 5.86 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.65 KB (0%)

/**
* Reevaulate the query against the current set of options.
*/
public rerun() {
Copy link
Member Author

@jerelmiller jerelmiller Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called this rerun, but am open to other names. Other names I considered:

  • reevaluate/evaluate
  • reexecute/execute

We use reobserve without options in a decent amount of tests and call this in reobserveCacheFirst so I figured there might be a use case for just trying to run the query again against the current set of options. I'm open to hearing otherwise and updating existing tests to observable['reobserve'] if need be, but I'm trying to avoid that. Calling setOptions({}) or refetch doesn't have the same intent as this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time, introducing a public api that does kinda the same as before feels a bit moot.

Do we think this will be used in userland?

Maybe at that point, it might be better to rename reobserve to rerun and remove setOptions?

@jerelmiller jerelmiller added auto-cleanup 🤖 and removed auto-cleanup 🤖 labels Mar 19, 2025
@@ -669,12 +669,22 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
};
}

/**
* Reevaluate against a new set of options which might cause a fetch.
*/
public setOptions(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider if setOptions works the way we'd like it to. The way its implemented is a big reason why I don't like the way setVariables works where it just resolves with the current value if there are no observers.

setVariables({ id: 2 }) with no observers will not call reobserve, but setOptions({ variables: { id: 2 } }) will which could result in a fetch.

I'd prefer some symmetry here if possible. In my mind, either we have all reobserve-based methods execute against reobserve, or we should require an active subscription to run all of them. Otherwise its difficult to know which ones might or might not fetch.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this feels like it should behave more like setVariables.

@jerelmiller
Copy link
Member Author

Discussed in person. We are going to do a few changes:

  • Keep reobserve, but remove the newNetworkStatus option. This will be managed by the higher-level calls that call reobserve
  • Get rid of setOptions. This is just a call to reobserve with new options
  • Remove rerun. This is just a call to reobserve with no argument

@jerelmiller jerelmiller force-pushed the jerel/private-reobserve branch from 30cb465 to 833f899 Compare March 20, 2025 18:35
@jerelmiller jerelmiller requested a review from a team as a code owner March 20, 2025 18:35
@jerelmiller jerelmiller removed the request for review from a team March 20, 2025 18:42
@jerelmiller
Copy link
Member Author

@phryneas this should be good to look at again as I've made the changes we discussed in our call.

@jerelmiller jerelmiller changed the title Make reobserve private Remove setOptions and tweak reobserve Mar 20, 2025
@jerelmiller jerelmiller force-pushed the jerel/private-reobserve branch from b2d8c43 to aa91ec6 Compare March 24, 2025 15:19
@github-actions github-actions bot added the auto-cleanup 🤖 label Mar 24, 2025
@jerelmiller jerelmiller force-pushed the jerel/private-reobserve branch from aa91ec6 to f15b031 Compare March 24, 2025 19:17
@jerelmiller jerelmiller merged commit 3868df8 into release-4.0 Mar 24, 2025
47 checks passed
@jerelmiller jerelmiller deleted the jerel/private-reobserve branch March 24, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants