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

chore: add docs for skipping an optimistic update via optimisticResponse #11461

Merged
merged 2 commits into from
Jan 3, 2024

Conversation

alessbell
Copy link
Contributor

Adds docs for #11410.

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@alessbell alessbell requested a review from a team as a code owner January 3, 2024 20:40
Copy link

changeset-bot bot commented Jan 3, 2024

⚠️ No Changeset found

Latest commit: 83cc833

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

github-actions bot commented Jan 3, 2024

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 38.21 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 46 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 43.55 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 33.97 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 31.9 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.24 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.22 KB (0%)
import { useQuery } from "dist/react/index.js" 5.2 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.27 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.51 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.58 KB (0%)
import { useMutation } from "dist/react/index.js" 3.51 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.73 KB (0%)
import { useSubscription } from "dist/react/index.js" 3.19 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 2.39 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.28 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 3.94 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 4.75 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.39 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 4.96 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.62 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.03 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 2.97 KB (0%)
import { useFragment } from "dist/react/index.js" 2.1 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.05 KB (0%)

Copy link

netlify bot commented Jan 3, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 83cc833
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/6595d64fd1666300083d126c
😎 Deploy Preview https://deploy-preview-11461--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
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Had some minor nits on the sentence, but otherwise looks great! Feel free to take/leave what makes sense to you.

@@ -73,6 +73,51 @@ As this example shows, the value of `optimisticResponse` is an object that match

5. Apollo Client notifies all affected queries again. The associated components re-render, but if the server's response matches our `optimisticResponse`, this is invisible to the user.

## Bailing out of an optimistic update

In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.
In some cases you may want to skip an optimistic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.

Typo 🙂

Suggested change
In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.
In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. To skip an update, pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.

I think it reads a touch nicer being a bit more direct here

Suggested change
In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.
In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to the `optimisticResponse` option and return the `IGNORE` sentinel object available to the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.

I think being a bit more explicit that this function is for the option and that IGNORE should be returned. Thoughts?

Suggested change
In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument passed to your `optimisticResponse` function to bail out of the optimistic update.
In some cases you may want to skip an optimisitic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. In order to skip an update, you can pass a function to `optimisticResponse` and use the `IGNORE` sentinel object available on the second argument to bail out of the optimistic update.

Since you've already mentioned that you're passing a function to the optimisticResponse option, no need to repeat it in the 2nd part of the sentence 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, +1 to all of these! Updated in 83cc833

@github-actions github-actions bot added the auto-cleanup 🤖 label Jan 3, 2024
@alessbell alessbell merged commit a604ac3 into release-3.9 Jan 3, 2024
36 checks passed
@alessbell alessbell deleted the docs/return-ignore-from-optimisticResponse branch January 3, 2024 22:31
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants