Skip to content

Conversation

@jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Mar 26, 2025

Closes #12482

Throws an error if a query or mutation does not emit a value before the link chain completes. This is usually a bug in the user's link chain and can have unintended consequences. By throwing, this makes the issue more visible and lets us clean up some areas of the codebase that would otherwise not be able to handle this situation.

This also addresses the issue where issuing a query with a standby fetch policy would throw an EmptyError and instead will resolve the query with data: undefined.

@jerelmiller jerelmiller requested a review from phryneas March 26, 2025 01:06
@changeset-bot
Copy link

changeset-bot bot commented Mar 26, 2025

🦋 Changeset detected

Latest commit: 9be41f9

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 26, 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: 56a402c94556cd08486afd72

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 26, 2025

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

commit: 9be41f9

obs.reobserve({ query, fetchPolicy: "standby" })
// TODO: Update this behavior
).rejects.toThrow(new EmptyError());
).resolves.toEqualStrictTyped({ data: undefined });
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 didn't add a changeset for this change since this was introduced with the RxJS switchover. I'd be happy to add one though if we'd like to point this out for the alpha release.

queryId,
options,
networkStatus
).observable.pipe(map(toQueryResult)),
Copy link
Member Author

Choose a reason for hiding this comment

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

Every area of the codebase that used fetchQuery converted the result to a QueryResult, so I refactored it to transform the value here instead.

return observable;
}

// TODO: catch `EmptyError` and rethrow as network error if `complete`
Copy link
Member Author

Choose a reason for hiding this comment

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

Nice to get rid of these todos 👍

// `value` can be `undefined` when the link chain only emits a complete
// event with no value which should be an error.
// https://github.com/apollographql/apollo-client/issues/12482
if (!value) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was here to guard against the link chain completing without emitting a value. Now that it results in an error condition, this check is no longer needed.

return lastValueFrom(
this.fetchObservableWithInfo(queryId, options, networkStatus).observable,
{ defaultValue: undefined }
) as TODO;
Copy link
Member Author

Choose a reason for hiding this comment

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

This TODO type felt great to get rid of 🙂

@jerelmiller jerelmiller force-pushed the jerel/update-query-type branch from 69db613 to 9a3957e Compare March 27, 2025 18:41
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch from 537d763 to 003daec Compare March 27, 2025 18:44
@jerelmiller jerelmiller force-pushed the jerel/update-query-type branch from 9a3957e to 271d756 Compare March 27, 2025 22:02
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch 2 times, most recently from 1e3f7ed to 6a54982 Compare March 27, 2025 22:18
@jerelmiller jerelmiller force-pushed the jerel/update-query-type branch from 59f6c06 to 07fd475 Compare March 28, 2025 16:40
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch from 6a54982 to a291b2b Compare March 28, 2025 16:50
@jerelmiller jerelmiller force-pushed the jerel/update-query-type branch from 07fd475 to 015d7d2 Compare March 31, 2025 14:44
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch from a291b2b to 4270fb9 Compare March 31, 2025 14:45
@jerelmiller jerelmiller force-pushed the jerel/update-query-type branch from 015d7d2 to 915d25e Compare March 31, 2025 16:29
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch from 4270fb9 to 9b55005 Compare March 31, 2025 16:30
@jerelmiller jerelmiller force-pushed the jerel/update-query-type branch from 915d25e to 482438f Compare March 31, 2025 16:35
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch from 9b55005 to 67430fd Compare March 31, 2025 16:37
@github-actions github-actions bot added the auto-cleanup 🤖 label Apr 1, 2025
@jerelmiller jerelmiller force-pushed the jerel/update-query-type branch from 36dc582 to 02d340e Compare April 1, 2025 15:05
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch from 67430fd to c60325a Compare April 1, 2025 15:08
Base automatically changed from jerel/update-query-type to release-4.0 April 1, 2025 15:13
@jerelmiller jerelmiller force-pushed the jerel/emit-error-on-empty branch from c60325a to 9be41f9 Compare April 1, 2025 15:19
@netlify
Copy link

netlify bot commented Apr 1, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 9be41f9
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67ec041a2a942e00082ea162
😎 Deploy Preview https://deploy-preview-12485--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.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 41.59 KB (+0.39% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 36.94 KB (+0.02% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.11 KB (+0.29% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 27.03 KB (+0.31% 🔺)
import { ApolloProvider } from "@apollo/client/react" 5.26 KB (+1.13% 🔺)
import { ApolloProvider } from "@apollo/client/react" (production) 964 B (0%)
import { useQuery } from "@apollo/client/react" 7.11 KB (+0.99% 🔺)
import { useQuery } from "@apollo/client/react" (production) 2.76 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 6.48 KB (+0.87% 🔺)
import { useLazyQuery } from "@apollo/client/react" (production) 2.16 KB (0%)
import { useMutation } from "@apollo/client/react" 6.45 KB (+0.97% 🔺)
import { useMutation } from "@apollo/client/react" (production) 2.1 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.74 KB (+0.9% 🔺)
import { useSubscription } from "@apollo/client/react" (production) 2.41 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.33 KB (+1.02% 🔺)
import { useSuspenseQuery } from "@apollo/client/react" (production) 4.01 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.15 KB (+0.84% 🔺)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.83 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.19 KB (+1% 🔺)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.87 KB (0%)
import { useReadQuery } from "@apollo/client/react" 5.94 KB (+1.14% 🔺)
import { useReadQuery } from "@apollo/client/react" (production) 1.61 KB (0%)
import { useFragment } from "@apollo/client/react" 5.98 KB (+0.91% 🔺)
import { useFragment } from "@apollo/client/react" (production) 1.66 KB (0%)

@jerelmiller jerelmiller merged commit d338303 into release-4.0 Apr 1, 2025
47 checks passed
@jerelmiller jerelmiller deleted the jerel/emit-error-on-empty branch April 1, 2025 15:25
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants