Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4450c94
Added rough draft of initial endpoint definition for infinite query
riqts Mar 1, 2024
e73be72
Added placeholder select and initiate functions where the merge and q…
riqts Mar 1, 2024
800c268
Theoretical slice added to buildSlice to potentially handle changing …
riqts Mar 1, 2024
f6b6b32
Added new endpointDefinition to createApi + module
riqts Mar 1, 2024
7bedf08
Added infiniteQueryThunks to core module file
riqts Mar 6, 2024
eeb4c4a
Initial implementation of executeEndpoint/Thunk with infiniteQuery
riqts Mar 6, 2024
bc03099
Extended infiniteQueryInitiate, added fetchNextPage and fetchPrevious…
riqts Mar 6, 2024
f3e112b
Added types for InfiniteQueryConfig
riqts Mar 6, 2024
469b09e
Shelf
riqts Mar 20, 2024
a53980b
Built out initial react hook definitions for InfiniteQuery
riqts Apr 23, 2024
f0cb14a
Added InfiniteQuerySubState with param and direction for slice operat…
riqts May 4, 2024
d40edcc
Set up Test Hook to actually test if next page gets data
riqts May 4, 2024
c27953d
Introduced correct typing and infiniteQuery hooks into buildHooks.ts
riqts May 4, 2024
b6700b7
Initiate handling and types for infiniteQuery
riqts May 4, 2024
535f92a
Added InfiniteQuery Selectors types for the hook
riqts May 4, 2024
68b7d61
Added necessary slice actions for inf query substate
riqts May 4, 2024
11d9800
Forced into the thunk working InfQuery handling for api proof of concept
riqts May 4, 2024
20e981d
Altered EndPointDefinition for type inference
riqts May 4, 2024
a8d1f20
Index has inf query type
riqts May 4, 2024
990a1bd
Cleanup imports from first pass
riqts May 4, 2024
a9c8277
add inf query definition option for module.ts
riqts May 4, 2024
3e8fb3c
Revert "Shelf"
riqts May 4, 2024
8896c80
Force selector type for infinite query test
riqts May 5, 2024
bbcf656
Pass through infinite query options
markerikson Sep 29, 2024
7bff5b6
Fix remaining TS issues
markerikson Sep 29, 2024
2e75387
Hack around TS issues
markerikson Sep 29, 2024
171f5cc
Try to fix exported types
markerikson Sep 29, 2024
5c8b6ec
Pass through correct data types for infinite queries
markerikson Oct 22, 2024
5195be7
Add an initial test for infinite query thunks
markerikson Oct 22, 2024
a66f2dc
Add `serializeQueryArgs` type support
markerikson Oct 23, 2024
7dafec8
Restructure infinite fetching logic to work with query or queryFn
markerikson Oct 24, 2024
8af2378
Export InfiniteData for type portability
markerikson Oct 24, 2024
ab2fca6
Separate QueryArg and PageParam types for infinite queries
markerikson Oct 24, 2024
b25267a
Require initialPageParam value
markerikson Oct 24, 2024
731f957
Add type tests for infinite query endpoints
markerikson Oct 27, 2024
71b4065
Fix type imports
markerikson Oct 27, 2024
7870a64
Fix infinite query hook data types
markerikson Oct 27, 2024
993024c
Fix useInfiniteQuery hook types and trigger behavior
markerikson Oct 27, 2024
a80d0fc
Fix exports
aryaemami59 Oct 27, 2024
9a0ffb2
Fix duplicate types
aryaemami59 Oct 27, 2024
822d0da
Fix TS issue caused by duplicate types in emitted type definitions
aryaemami59 Oct 27, 2024
4efc718
Pass through `initialPageParam` on thunk dispatch
markerikson Oct 27, 2024
bb32ba8
Change 'backwards' to 'backward'
markerikson Oct 27, 2024
9937291
Test getPreviousParam behavior
markerikson Oct 27, 2024
f9df3b0
Separate out useInfiniteQuery tests
markerikson Oct 27, 2024
0a32a5c
Only pass initialPageParams option through query hook
markerikson Oct 27, 2024
2f02f7c
Fix bad rebase of exports
markerikson Nov 29, 2024
aec2719
Add RTL/react-render-stream
markerikson Nov 29, 2024
4ee0f7f
Rewrite infinite query test to use render-stream
markerikson Nov 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@size-limit/webpack": "^11.0.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.0.1",
"@testing-library/react-render-stream": "^1.0.3",
"@testing-library/user-event": "^14.5.2",
"@types/babel__core": "^7.20.5",
"@types/babel__helper-module-imports": "^7.18.3",
Expand Down
84 changes: 73 additions & 11 deletions packages/toolkit/src/query/core/apiState.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { SerializedError } from '@reduxjs/toolkit'
import type { BaseQueryError } from '../baseQueryTypes'
import type {
QueryDefinition,
MutationDefinition,
EndpointDefinitions,
BaseEndpointDefinition,
ResultTypeFrom,
EndpointDefinitions,
InfiniteQueryDefinition,
MutationDefinition,
PageParamFrom,
QueryArgFrom,
QueryDefinition,
ResultTypeFrom,
} from '../endpointDefinitions'
import type { Id, WithRequiredProp } from '../tsHelpers'

Expand All @@ -28,6 +30,35 @@ export type RefetchConfigOptions = {
refetchOnFocus: boolean
}

export type GetNextPageParamFunction<TPageParam, TQueryFnData> = (
lastPage: TQueryFnData,
allPages: Array<TQueryFnData>,
lastPageParam: TPageParam,
allPageParams: Array<TPageParam>,
) => TPageParam | undefined | null

export type GetPreviousPageParamFunction<TPageParam, TQueryFnData> = (
firstPage: TQueryFnData,
allPages: Array<TQueryFnData>,
firstPageParam: TPageParam,
allPageParams: Array<TPageParam>,
) => TPageParam | undefined | null

export type InfiniteQueryConfigOptions<TQueryFnData, TPageParam> = {
initialPageParam: TPageParam
/**
* This function can be set to automatically get the previous cursor for infinite queries.
* The result will also be used to determine the value of `hasPreviousPage`.
*/
getPreviousPageParam?: GetPreviousPageParamFunction<TPageParam, TQueryFnData>
getNextPageParam: GetNextPageParamFunction<TPageParam, TQueryFnData>
}

export interface InfiniteData<TData, TPageParam> {
pages: Array<TData>
pageParams: Array<TPageParam>
}

/**
* Strings describing the query state at any given time.
*/
Expand Down Expand Up @@ -133,7 +164,10 @@ export type MutationKeys<Definitions extends EndpointDefinitions> = {
: never
}[keyof Definitions]

type BaseQuerySubState<D extends BaseEndpointDefinition<any, any, any>> = {
type BaseQuerySubState<
D extends BaseEndpointDefinition<any, any, any>,
DataType = ResultTypeFrom<D>,
> = {
/**
* The argument originally passed into the hook or `initiate` action call
*/
Expand All @@ -145,7 +179,7 @@ type BaseQuerySubState<D extends BaseEndpointDefinition<any, any, any>> = {
/**
* The received data from the query
*/
data?: ResultTypeFrom<D>
data?: DataType
/**
* The received error if applicable
*/
Expand All @@ -166,21 +200,31 @@ type BaseQuerySubState<D extends BaseEndpointDefinition<any, any, any>> = {
* Time that the latest query was fulfilled
*/
fulfilledTimeStamp?: number
/**
* Infinite Query Specific substate properties
*/
hasNextPage?: boolean
hasPreviousPage?: boolean
direction?: 'forward' | 'backward'
param?: QueryArgFrom<D>
}

export type QuerySubState<D extends BaseEndpointDefinition<any, any, any>> = Id<
export type QuerySubState<
D extends BaseEndpointDefinition<any, any, any>,
DataType = ResultTypeFrom<D>,
> = Id<
| ({
status: QueryStatus.fulfilled
} & WithRequiredProp<
BaseQuerySubState<D>,
BaseQuerySubState<D, DataType>,
'data' | 'fulfilledTimeStamp'
> & { error: undefined })
| ({
status: QueryStatus.pending
} & BaseQuerySubState<D>)
} & BaseQuerySubState<D, DataType>)
| ({
status: QueryStatus.rejected
} & WithRequiredProp<BaseQuerySubState<D>, 'error'>)
} & WithRequiredProp<BaseQuerySubState<D, DataType>, 'error'>)
| {
status: QueryStatus.uninitialized
originalArgs?: undefined
Expand All @@ -193,6 +237,21 @@ export type QuerySubState<D extends BaseEndpointDefinition<any, any, any>> = Id<
}
>

export type InfiniteQuerySubState<
D extends BaseEndpointDefinition<any, any, any>,
> =
D extends InfiniteQueryDefinition<any, any, any, any, any>
? QuerySubState<D, InfiniteData<ResultTypeFrom<D>, PageParamFrom<D>>> & {
// TODO: These shouldn't be optional
hasNextPage?: boolean
hasPreviousPage?: boolean
isFetchingNextPage?: boolean
isFetchingPreviousPage?: boolean
param?: PageParamFrom<D>
direction?: 'forward' | 'backward'
}
: never

type BaseMutationSubState<D extends BaseEndpointDefinition<any, any, any>> = {
requestId: string
data?: ResultTypeFrom<D>
Expand Down Expand Up @@ -249,7 +308,10 @@ export type InvalidationState<TagTypes extends string> = {
}

export type QueryState<D extends EndpointDefinitions> = {
[queryCacheKey: string]: QuerySubState<D[string]> | undefined
[queryCacheKey: string]:
| QuerySubState<D[string]>
| InfiniteQuerySubState<D[string]>
| undefined
}

export type SubscriptionState = {
Expand Down
Loading