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

Changed typings of updateQuery's previousQueryResult to be potentially undefined #12276

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Cellule
Copy link

@Cellule Cellule commented Jan 15, 2025

Related to #12228

There's an outstanding issue where previousQueryResult sometimes, flakily, ends up undefined
This change aims to have the typings reflect the actual runtime behavior allowing devs to write safe code that can handle the missing previousQueryResult
An alternative could be to simply not call mapFn if previousQueryResult is missing. While neither is ideal nor fixes the underlying issue of "why" previousQueryResult is undefined. At least it would avoid bad crashes.

I've been rolling with this patch for years now and I haven't seen any bad side-effects so far. As far as I can tell, the case where previousQueryResult can be safely ignored and is likely going to be called again with actual data when it matters

Typings Update for updateQuery:

  • Changed typings of updateQuery's previousQueryResult to be potentially undefined in @apollo/client.
  • Updated updateQuery method in src/core/ObservableQuery.ts to reflect the new typings.
  • Modified UpdateQueryFn type in src/core/watchQueryOptions.ts to allow previousQueryResult to be undefined.
  • Updated ObservableQueryFields interface in src/react/types/types.ts to reflect the new typings.

VSCode Configuration:

  • Added editor.codeActionsOnSave setting to disable organizing imports on save in .vscode/settings.json.

Copy link

netlify bot commented Jan 15, 2025

👷 Deploy request for apollo-client-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6af8e64

@svc-apollo-docs
Copy link

svc-apollo-docs commented Jan 15, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 126f5a5c81a60f85bbd31129

Copy link

changeset-bot bot commented Jan 15, 2025

🦋 Changeset detected

Latest commit: 6af8e64

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 Patch

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

@Cellule Cellule force-pushed the update-query-typings branch from 3a4c44f to d9cfe5d Compare January 15, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants