-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Adds support for skipToken
in options for useSuspenseQuery
and useBackgroundQuery
and soft deprecates skip
option
#11112
Conversation
src/react/hooks/useReadQuery.ts
Outdated
} from '../cache/QueryReference.js'; | ||
import { __use } from './internal/index.js'; | ||
import { toApolloError } from './useSuspenseQuery.js'; | ||
import { invariant } from '../../utilities/globals/index.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I happened to notice we were importing this function from the wrong place. This has been updated to ensure its using the wrapped version.
}, | ||
]; | ||
}, [queryRef, fetchMore, refetch]); | ||
return [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no reason to memo
this return tuple since the tuple itself didn't need to be referentially stable, just the items in the tuple. Typical usage of this hook will destructure this tuple, so no need to memoize it.
Co-authored-by: Lenz Weber-Tronic <lorenz.weber-tronic@apollographql.com>
Co-authored-by: Lenz Weber-Tronic <lorenz.weber-tronic@apollographql.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love some minor changes in tests, but generally this is good to go!
}); | ||
|
||
// Toggle skip to `true` | ||
await act(() => user.click(screen.getByText('Toggle skip'))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Independently of skip
- why would another network request happen here in the first place? Do we need to change variables to provoke that without skip
a request would be provoked here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more that I wanted to prove that switching back to skip: true
didn't itself have any adverse effects such as tangling it up with some other value, or that it wasn't just a "skips the first time it's true" type of thing. skip
is a suspenseful option, so it was just an extra check to ensure I wasn't suspending more than necessary.
You're right though, switching variables is probably a more solid way to show off that it does indeed skip. Let me see if I can make this change to make it more obvious what this test is trying to accomplish.
…nsure skip behavior is working
Closes #11093
Adds support for a new
skipToken
sentinel that can be passed as options touseSuspenseQuery
anduseBackgroundQuery
. This works in place ofskip
for both of these hooks. As such, theskip
option is now labeled asdeprecated
to nudge people to use this feature, which is generally more type-safe than theskip
option.Breaking change
This PR also changes the way
queryRef
is returned whenskip
istrue
orskipToken
is used withuseBackgroundQuery
. Previously, aqueryRef
would always be returned, regardless of whether query execution was skipped. This has been updated to conditionally return aqueryRef
only when query execution is enabled.undefined
is returned when initializing the hook skipped.Before
After
Checklist: