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

[Refactor] Move tracking of networkStatus into ObservableQuery #12407

Merged
merged 25 commits into from
Mar 11, 2025

Conversation

jerelmiller
Copy link
Member

networkStatus is really only useful for ObservableQuery as all other promise-based APIs will have a final networkStatus of either ready or error. As such, the fine-grained tracking of networkStatus has been moved to ObservableQuery. This helps us reduce the reliance on QueryInfo some more in an effort to one day eliminate it.

Copy link

changeset-bot bot commented Mar 6, 2025

🦋 Changeset detected

Latest commit: 1485c05

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 6, 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: 5c9d2b4eaa91bec4024124a6

@@ -1312,7 +1312,6 @@ describe("optimistic mutation results", () => {
});

it("will handle dependent updates", async () => {
expect.assertions(1);
Copy link
Member Author

@jerelmiller jerelmiller Mar 6, 2025

Choose a reason for hiding this comment

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

There is not an assertion hidden in a callback so there is no way the assertion will be missed. This was fairly useless so I removed it.

Copy link

pkg-pr-new bot commented Mar 6, 2025

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

commit: 67eb2aa

@@ -284,7 +284,7 @@ describe("ObservableQuery", () => {
await expect(stream).toEmitApolloQueryResult({
data: undefined,
loading: true,
networkStatus: NetworkStatus.setVariables,
networkStatus: NetworkStatus.refetch,
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 figure out if we like this change. When calling refetch with new variables, the networkStatus would get reported as setVariables rather than refetch, even though refetch was the explicitly requested networkStatus passed to reobserve.

I suppose it depends on whether we view the setVariables status as more specific than refetch in the case of changing variables via refetch.

Copy link
Member

Choose a reason for hiding this comment

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

I think this would be fine, at least it reflects better which method you called.

@jerelmiller jerelmiller force-pushed the jerel/network-status-refactor branch from b7cdc81 to 3e3585f Compare March 10, 2025 17:12
Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

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

Looks good!

});

const readCache = () => queryInfo.getDiff();

const resultsFromCache = (
diff: Cache.DiffResult<TData>,
networkStatus = queryInfo.networkStatus || NetworkStatus.loading
networkStatus = newNetworkStatus
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: investigate if this ever can cause a race condition now that this is static and doesn't track external mutations.

Base automatically changed from jerel/rxjs to release-4.0 March 11, 2025 17:14
@jerelmiller jerelmiller force-pushed the jerel/network-status-refactor branch from 3e3585f to 25a7177 Compare March 11, 2025 17:49
Copy link

netlify bot commented Mar 11, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 1485c05
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67d07b5256de80000949df79
😎 Deploy Preview https://deploy-preview-12407--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 11, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.09 KB (-0.12% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.68 KB (-0.2% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.66 KB (-0.12% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 28.22 KB (-0.07% 🔽)
import { ApolloProvider } from "@apollo/client/react" 5.14 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 1.05 KB (0%)
import { useQuery } from "@apollo/client/react" 7.26 KB (0%)
import { useQuery } from "@apollo/client/react" (production) 3.19 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 7.6 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 3.5 KB (0%)
import { useMutation } from "@apollo/client/react" 6.51 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 2.41 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.93 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 2.85 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.19 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 4.12 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.03 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.96 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.08 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 4.02 KB (0%)
import { useReadQuery } from "@apollo/client/react" 5.73 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.63 KB (0%)
import { useFragment } from "@apollo/client/react" 5.78 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.68 KB (0%)

@jerelmiller jerelmiller force-pushed the jerel/network-status-refactor branch from c087aa9 to 67eb2aa Compare March 11, 2025 18:02
@jerelmiller jerelmiller merged commit 8b1390b into release-4.0 Mar 11, 2025
37 checks passed
@jerelmiller jerelmiller deleted the jerel/network-status-refactor branch March 11, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants