Skip to content

Set loading: false with cache-only queries with no data in the cache #12705

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

Merged
merged 11 commits into from
Jun 18, 2025

Conversation

jerelmiller
Copy link
Member

Supersedes #12021

Sets the initial loading state to false for a cache-only query when no data is in the cache.

@jerelmiller jerelmiller requested a review from phryneas June 17, 2025 04:32
Copy link

changeset-bot bot commented Jun 17, 2025

🦋 Changeset detected

Latest commit: b1e1358

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

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

Copy link

pkg-pr-new bot commented Jun 17, 2025

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@12705

commit: 1249686

Copy link
Contributor

github-actions bot commented Jun 17, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.25 KB (-0.07% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.46 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.5 KB (-0.03% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 27.06 KB (-0.1% 🔽)
import { ApolloProvider } from "@apollo/client/react" 5.58 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 963 B (0%)
import { useQuery } from "@apollo/client/react" 6.85 KB (0%)
import { useQuery } from "@apollo/client/react" (production) 2.2 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 6.76 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 2.14 KB (0%)
import { useMutation } from "@apollo/client/react" 6.11 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 1.48 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.43 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 1.8 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.23 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.61 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 7.97 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.38 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 7.97 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.36 KB (0%)
import { useReadQuery } from "@apollo/client/react" 6.25 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.62 KB (0%)
import { useFragment } from "@apollo/client/react" 6.3 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.68 KB (0%)

Copy link
Member Author

Choose a reason for hiding this comment

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

I just realized we should probably test a cache-only query with a local resolver. Local resolvers are async so that might be the only case where we see a loading: true.

Copy link
Member

Choose a reason for hiding this comment

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

Good idea! Generally I'm pretty sure it wouldn't cause a loading state, since we only take link/network asynchronity into account for the loading state, but please go ahead and add a test to document that :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated. cache-only will only return cached data for local fields, so local resolvers are never run. This is at least now documented in a test! This means that cache-only queries will never return a loading: true state. I'm happy with that.

Copy link
Member

Choose a reason for hiding this comment

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

Good idea! Generally I'm pretty sure it wouldn't cause a loading state, since we only take link/network asynchronity into account for the loading state, but please go ahead and add a test to document that :)

@github-actions github-actions bot added the auto-cleanup 🤖 label Jun 17, 2025
@jerelmiller jerelmiller force-pushed the jerel/cache-only-request branch from a10a9a2 to 9775f78 Compare June 18, 2025 02:41
@jerelmiller jerelmiller merged commit a60f411 into release-4.0 Jun 18, 2025
31 of 32 checks passed
@jerelmiller jerelmiller deleted the jerel/cache-only-request branch June 18, 2025 03:04
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.

2 participants