@@ -10,6 +10,7 @@ import type {
1010} from '@seamapi/http/connect'
1111import type { ActionAttempt } from '@seamapi/types/connect'
1212import {
13+ type QueryKey ,
1314 useInfiniteQuery ,
1415 type UseInfiniteQueryOptions ,
1516 type UseInfiniteQueryResult ,
@@ -29,19 +30,25 @@ export function useSeamInfiniteQuery<
2930 T extends SeamHttpEndpointPaginatedQueryPaths ,
3031> (
3132 endpointPath : T ,
32- parameters ? : UseSeamInfiniteQueryParameters < T > ,
33+ parameters : UseSeamInfiniteQueryParameters < T > = { } ,
3334 options : Parameters < SeamHttpEndpoints [ T ] > [ 1 ] &
3435 QueryOptions < QueryData < T > , QueryError < T > > = { }
35- ) : UseSeamInfiniteQueryResult < T > {
36+ ) : UseSeamInfiniteQueryResult < T > & { queryKey : QueryKey } {
3637 const { endpointClient : client , queryKeyPrefixes } = useSeamClient ( )
37- return useInfiniteQuery ( {
38+
39+ if ( 'page_cursor' in ( parameters ?? { } ) ) {
40+ throw new Error ( 'Cannot use page_cursor with useSeamInfiniteQuery' )
41+ }
42+
43+ const queryKey = [
44+ ...queryKeyPrefixes ,
45+ ...endpointPath . split ( '/' ) . filter ( ( v ) => v !== '' ) ,
46+ parameters ?? { } ,
47+ ]
48+ const result = useInfiniteQuery ( {
3849 enabled : client != null ,
3950 ...options ,
40- queryKey : [
41- ...queryKeyPrefixes ,
42- ...endpointPath . split ( '/' ) . filter ( ( v ) => v !== '' ) ,
43- parameters ,
44- ] ,
51+ queryKey,
4552 initialPageParam : null ,
4653 getNextPageParam : ( lastPage ) => lastPage . nextPageCursor ,
4754 queryFn : async ( { pageParam } ) => {
@@ -72,6 +79,7 @@ export function useSeamInfiniteQuery<
7279 }
7380 } ,
7481 } )
82+ return { ...result , queryKey }
7583}
7684
7785interface QueryData < T extends SeamHttpEndpointPaginatedQueryPaths > {
0 commit comments