Skip to content

Commit 619c7ff

Browse files
committed
Add infinite queries to type portability examples
1 parent c7c02ac commit 619c7ff

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

examples/type-portability/bundler/src/app/services/posts.ts

+25
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ export const postsApi = apiSlice.injectEndpoints({
7373
getErrorProne: build.query<{ success: boolean }, void>({
7474
query: () => 'error-prone',
7575
}),
76+
getInfinitePosts: build.infiniteQuery<PostsResponse, void, number>({
77+
queryFn: ({ pageParam = 0 }) => ({
78+
data: [],
79+
}),
80+
infiniteQueryOptions: {
81+
initialPageParam: 0,
82+
getNextPageParam: (lastPage) =>
83+
lastPage.length === 0 ? undefined : lastPage[lastPage.length - 1].id,
84+
},
85+
}),
7686
}),
7787
})
7888

@@ -87,6 +97,7 @@ export const {
8797
useLazyGetErrorProneQuery,
8898
useLazyGetPostQuery,
8999
useLazyGetPostsQuery,
100+
useGetInfinitePostsInfiniteQuery,
90101
endpoints,
91102
enhanceEndpoints,
92103
injectEndpoints,
@@ -106,6 +117,7 @@ export const {
106117
getPosts,
107118
login,
108119
updatePost,
120+
getInfinitePosts,
109121
} = endpoints
110122

111123
export const {
@@ -182,6 +194,19 @@ export const {
182194
useMutation: _____useMutation,
183195
} = updatePost
184196

197+
export const {
198+
Types: ______Types,
199+
initiate: ______initiate,
200+
matchFulfilled: ______matchFulfilled,
201+
matchPending: ______matchPending,
202+
matchRejected: ______matchRejected,
203+
name: ______name,
204+
select: ______select,
205+
useInfiniteQueryState: ______useQueryState,
206+
useInfiniteQuery: ______useQuery,
207+
useInfiniteQuerySubscription: ______useQuerySubscription,
208+
} = getInfinitePosts
209+
185210
export const {
186211
internal_getRTKQSubscriptions,
187212
middlewareRegistered,

examples/type-portability/bundler/src/features/posts/PostsManager.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useGetErrorProneQuery,
99
useGetPostsQuery,
1010
useLoginMutation,
11+
useGetInfinitePostsInfiniteQuery,
1112
} from '../../app/services/posts'
1213
import { logout, selectIsAuthenticated } from '../auth/authSlice'
1314
import { PostDetail } from './PostDetail'
@@ -70,6 +71,7 @@ export const PostListItem = ({
7071

7172
export const PostList = () => {
7273
const { data: posts, isLoading } = useGetPostsQuery()
74+
useGetInfinitePostsInfiniteQuery()
7375
const navigate = useNavigate()
7476

7577
if (isLoading) {

examples/type-portability/nodenext-cjs/src/app/services/posts.ts

+27
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ namespace postsModule {
7676
getErrorProne: build.query<{ success: boolean }, void>({
7777
query: () => 'error-prone',
7878
}),
79+
getInfinitePosts: build.infiniteQuery<PostsResponse, void, number>({
80+
queryFn: ({ pageParam = 0 }) => ({
81+
data: [],
82+
}),
83+
infiniteQueryOptions: {
84+
initialPageParam: 0,
85+
getNextPageParam: (lastPage) =>
86+
lastPage.length === 0
87+
? undefined
88+
: lastPage[lastPage.length - 1].id,
89+
},
90+
}),
7991
}),
8092
})
8193

@@ -90,6 +102,7 @@ namespace postsModule {
90102
useLazyGetErrorProneQuery,
91103
useLazyGetPostQuery,
92104
useLazyGetPostsQuery,
105+
useGetInfinitePostsInfiniteQuery,
93106
endpoints,
94107
enhanceEndpoints,
95108
injectEndpoints,
@@ -109,6 +122,7 @@ namespace postsModule {
109122
getPosts,
110123
login,
111124
updatePost,
125+
getInfinitePosts,
112126
} = endpoints
113127

114128
export const {
@@ -185,6 +199,19 @@ namespace postsModule {
185199
useMutation: _____useMutation,
186200
} = updatePost
187201

202+
export const {
203+
Types: ______Types,
204+
initiate: ______initiate,
205+
matchFulfilled: ______matchFulfilled,
206+
matchPending: ______matchPending,
207+
matchRejected: ______matchRejected,
208+
name: ______name,
209+
select: ______select,
210+
useInfiniteQueryState: ______useQueryState,
211+
useInfiniteQuery: ______useQuery,
212+
useInfiniteQuerySubscription: ______useQuerySubscription,
213+
} = getInfinitePosts
214+
188215
export const {
189216
internal_getRTKQSubscriptions,
190217
middlewareRegistered,

examples/type-portability/nodenext-cjs/src/features/posts/PostsManager.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import useAddPostMutation = postsModule.useAddPostMutation
1818
import useGetErrorProneQuery = postsModule.useGetErrorProneQuery
1919
import useGetPostsQuery = postsModule.useGetPostsQuery
2020
import useLoginMutation = postsModule.useLoginMutation
21+
import useGetInfinitePostsInfiniteQuery = postsModule.useGetInfinitePostsInfiniteQuery
2122
import logout = authSliceModule.logout
2223
import selectIsAuthenticated = authSliceModule.selectIsAuthenticated
2324

@@ -81,6 +82,7 @@ const PostListItem = ({
8182

8283
const PostList = () => {
8384
const { data: posts, isLoading } = useGetPostsQuery()
85+
useGetInfinitePostsInfiniteQuery()
8486
const navigate = useNavigate()
8587

8688
if (isLoading) {

examples/type-portability/nodenext-esm/src/app/services/posts.ts

+25
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ export const postsApi = apiSlice.injectEndpoints({
7373
getErrorProne: build.query<{ success: boolean }, void>({
7474
query: () => 'error-prone',
7575
}),
76+
getInfinitePosts: build.infiniteQuery<PostsResponse, void, number>({
77+
queryFn: ({ pageParam = 0 }) => ({
78+
data: [],
79+
}),
80+
infiniteQueryOptions: {
81+
initialPageParam: 0,
82+
getNextPageParam: (lastPage) =>
83+
lastPage.length === 0 ? undefined : lastPage[lastPage.length - 1].id,
84+
},
85+
}),
7686
}),
7787
})
7888

@@ -87,6 +97,7 @@ export const {
8797
useLazyGetErrorProneQuery,
8898
useLazyGetPostQuery,
8999
useLazyGetPostsQuery,
100+
useGetInfinitePostsInfiniteQuery,
90101
endpoints,
91102
enhanceEndpoints,
92103
injectEndpoints,
@@ -106,6 +117,7 @@ export const {
106117
getPosts,
107118
login,
108119
updatePost,
120+
getInfinitePosts,
109121
} = endpoints
110122

111123
export const {
@@ -182,6 +194,19 @@ export const {
182194
useMutation: _____useMutation,
183195
} = updatePost
184196

197+
export const {
198+
Types: ______Types,
199+
initiate: ______initiate,
200+
matchFulfilled: ______matchFulfilled,
201+
matchPending: ______matchPending,
202+
matchRejected: ______matchRejected,
203+
name: ______name,
204+
select: ______select,
205+
useInfiniteQueryState: ______useQueryState,
206+
useInfiniteQuery: ______useQuery,
207+
useInfiniteQuerySubscription: ______useQuerySubscription,
208+
} = getInfinitePosts
209+
185210
export const {
186211
internal_getRTKQSubscriptions,
187212
middlewareRegistered,

examples/type-portability/nodenext-esm/src/features/posts/PostsManager.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Post } from '../../app/services/posts.js'
66
import {
77
useAddPostMutation,
88
useGetErrorProneQuery,
9+
useGetInfinitePostsInfiniteQuery,
910
useGetPostsQuery,
1011
useLoginMutation,
1112
} from '../../app/services/posts.js'
@@ -70,6 +71,7 @@ export const PostListItem = ({
7071

7172
export const PostList = () => {
7273
const { data: posts, isLoading } = useGetPostsQuery()
74+
useGetInfinitePostsInfiniteQuery()
7375
const navigate = useNavigate()
7476

7577
if (isLoading) {

0 commit comments

Comments
 (0)