Skip to content

Commit 7a2ee50

Browse files
committed
Use build consistently instead of builder
1 parent 62b4cad commit 7a2ee50

File tree

5 files changed

+48
-51
lines changed

5 files changed

+48
-51
lines changed

docs/rtk-query/api/createApi.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import type { Pokemon } from './types'
3939
export const pokemonApi = createApi({
4040
reducerPath: 'pokemonApi',
4141
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
42-
endpoints: (builder) => ({
43-
getPokemonByName: builder.query<Pokemon, string>({
42+
endpoints: (build) => ({
43+
getPokemonByName: build.query<Pokemon, string>({
4444
query: (name) => `pokemon/${name}`,
4545
}),
4646
}),
@@ -148,7 +148,7 @@ See [Endpoint Definition Parameters](#endpoint-definition-parameters) for detail
148148
149149
#### Query endpoint definition
150150
151-
Query endpoints (defined with `builder.query()`) are used to cache data fetched from the server.
151+
Query endpoints (defined with `build.query()`) are used to cache data fetched from the server.
152152
153153
You must specify either a `query` field (which will use the API's `baseQuery` to make a request), or a `queryFn` function with your own async logic. All other fields are optional.
154154
@@ -226,9 +226,9 @@ export type QueryDefinition<
226226
227227
#### Infinite Query endpoint definition
228228
229-
Infinite query endpoints (defined with `builder.infiniteQuery()`) are used to cache multi-page data sets from the server. They have all the same callbacks and options as standard query endpoints, but also require an additional [`infiniteQueryOptions`](#infinitequeryoptions) field to specify how to calculate the unique parameters to fetch each page.
229+
Infinite query endpoints (defined with `build.infiniteQuery()`) are used to cache multi-page data sets from the server. They have all the same callbacks and options as standard query endpoints, but also require an additional [`infiniteQueryOptions`](#infinitequeryoptions) field to specify how to calculate the unique parameters to fetch each page.
230230
231-
For infinite query endpoints, there is a separation between the "query arg" used for the cache key, and the "page param" used to fetch a specific page. For example, a Pokemon API endpoint might have a string query arg like `"fire"` as the query arg, but use a page number as the param to determine which page to fetch out of the results. This means the page param is what will be passed to your `query` or `queryFn` methods.
231+
For infinite query endpoints, there is a separation between the "query arg" used for the cache key, and the "page param" used to fetch a specific page. For example, a Pokemon API endpoint might have a string query arg like `"fire"` , but use a page number as the param to determine which page to fetch out of the results. This means the page param is what will be passed to your `query` or `queryFn` methods.
232232
233233
```ts title="Infinite Query endpoint definition" no-transpile
234234
export type PageParamFunction<DataType, PageParam> = (
@@ -284,7 +284,7 @@ export type InfiniteQueryDefinition<
284284
285285
#### Mutation endpoint definition
286286
287-
Mutation endpoints (defined with `builder.mutation()`) are used to send updates to the server, and force invalidation and refetching of query endpoints.
287+
Mutation endpoints (defined with build.mutation()`) are used to send updates to the server, and force invalidation and refetching of query endpoints.
288288

289289
As with queries, you must specify either the `query` option or the `queryFn` async method.
290290

packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ export type MutationLifecycleApi<
248248
* baseQuery: fetchBaseQuery({ baseUrl: 'https://dummyjson.com' }),
249249
* reducerPath: 'postsApi',
250250
* tagTypes: ['Posts'],
251-
* endpoints: (builder) => ({
252-
* getPosts: builder.query<PostsApiResponse, void>({
251+
* endpoints: (build) => ({
252+
* getPosts: build.query<PostsApiResponse, void>({
253253
* query: () => `/posts`,
254254
* }),
255255
*
256-
* getPostById: builder.query<Post, QueryArgument>({
256+
* getPostById: build.query<Post, QueryArgument>({
257257
* query: (postId) => `/posts/${postId}`,
258258
* }),
259259
* }),
@@ -283,8 +283,8 @@ export type MutationLifecycleApi<
283283
* }
284284
*
285285
* export const extendedApiSlice = baseApiSlice.injectEndpoints({
286-
* endpoints: (builder) => ({
287-
* getPostsByUserId: builder.query<PostsApiResponse, QueryArgument>({
286+
* endpoints: (build) => ({
287+
* getPostsByUserId: build.query<PostsApiResponse, QueryArgument>({
288288
* query: (userId) => `/posts/user/${userId}`,
289289
*
290290
* onQueryStarted: updatePostOnFulfilled,
@@ -346,12 +346,12 @@ export type TypedQueryOnQueryStarted<
346346
* baseQuery: fetchBaseQuery({ baseUrl: 'https://dummyjson.com' }),
347347
* reducerPath: 'postsApi',
348348
* tagTypes: ['Posts'],
349-
* endpoints: (builder) => ({
350-
* getPosts: builder.query<PostsApiResponse, void>({
349+
* endpoints: (build) => ({
350+
* getPosts: build.query<PostsApiResponse, void>({
351351
* query: () => `/posts`,
352352
* }),
353353
*
354-
* getPostById: builder.query<Post, number>({
354+
* getPostById: build.query<Post, number>({
355355
* query: (postId) => `/posts/${postId}`,
356356
* }),
357357
* }),
@@ -377,8 +377,8 @@ export type TypedQueryOnQueryStarted<
377377
* }
378378
*
379379
* export const extendedApiSlice = baseApiSlice.injectEndpoints({
380-
* endpoints: (builder) => ({
381-
* addPost: builder.mutation<Post, Omit<QueryArgument, 'id'>>({
380+
* endpoints: (build) => ({
381+
* addPost: build.mutation<Post, Omit<QueryArgument, 'id'>>({
382382
* query: (body) => ({
383383
* url: `posts/add`,
384384
* method: 'POST',
@@ -388,7 +388,7 @@ export type TypedQueryOnQueryStarted<
388388
* onQueryStarted: updatePostOnFulfilled,
389389
* }),
390390
*
391-
* updatePost: builder.mutation<Post, QueryArgument>({
391+
* updatePost: build.mutation<Post, QueryArgument>({
392392
* query: ({ id, ...patch }) => ({
393393
* url: `post/${id}`,
394394
* method: 'PATCH',

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ export interface InfiniteQueryExtraOptions<
612612
*
613613
* ```ts
614614
* // codeblock-meta title="infiniteQueryOptions example"
615-
* getInfinitePokemonWithMax: builder.infiniteQuery<
615+
* getInfinitePokemonWithMax: build.infiniteQuery<
616616
Pokemon[],
617617
string,
618618
number

packages/toolkit/src/query/tests/infiniteQueries.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ describe('Infinite queries', () => {
1515

1616
const pokemonApi = createApi({
1717
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
18-
endpoints: (builder) => ({
19-
getInfinitePokemon: builder.infiniteQuery<Pokemon[], string, number>({
18+
endpoints: (build) => ({
19+
getInfinitePokemon: build.infiniteQuery<Pokemon[], string, number>({
2020
infiniteQueryOptions: {
2121
initialPageParam: 0,
2222
getNextPageParam: (

packages/toolkit/src/query/tests/infiniteQueries.test.ts

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ describe('Infinite queries', () => {
3737

3838
const pokemonApi = createApi({
3939
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
40-
endpoints: (builder) => ({
41-
getInfinitePokemon: builder.infiniteQuery<Pokemon[], string, number>({
40+
endpoints: (build) => ({
41+
getInfinitePokemon: build.infiniteQuery<Pokemon[], string, number>({
4242
infiniteQueryOptions: {
4343
initialPageParam: 0,
4444
getNextPageParam: (
4545
lastPage,
4646
allPages,
47-
// Page param type should be `number`
4847
lastPageParam,
4948
allPageParams,
5049
) => lastPageParam + 1,
@@ -61,34 +60,32 @@ describe('Infinite queries', () => {
6160
return `https://example.com/listItems?page=${pageParam}`
6261
},
6362
}),
64-
getInfinitePokemonWithMax: builder.infiniteQuery<
65-
Pokemon[],
66-
string,
67-
number
68-
>({
69-
infiniteQueryOptions: {
70-
initialPageParam: 0,
71-
maxPages: 3,
72-
getNextPageParam: (
73-
lastPage,
74-
allPages,
75-
lastPageParam,
76-
allPageParams,
77-
) => lastPageParam + 1,
78-
getPreviousPageParam: (
79-
firstPage,
80-
allPages,
81-
firstPageParam,
82-
allPageParams,
83-
) => {
84-
return firstPageParam > 0 ? firstPageParam - 1 : undefined
63+
getInfinitePokemonWithMax: build.infiniteQuery<Pokemon[], string, number>(
64+
{
65+
infiniteQueryOptions: {
66+
initialPageParam: 0,
67+
maxPages: 3,
68+
getNextPageParam: (
69+
lastPage,
70+
allPages,
71+
lastPageParam,
72+
allPageParams,
73+
) => lastPageParam + 1,
74+
getPreviousPageParam: (
75+
firstPage,
76+
allPages,
77+
firstPageParam,
78+
allPageParams,
79+
) => {
80+
return firstPageParam > 0 ? firstPageParam - 1 : undefined
81+
},
82+
},
83+
query(pageParam) {
84+
return `https://example.com/listItems?page=${pageParam}`
8585
},
8686
},
87-
query(pageParam) {
88-
return `https://example.com/listItems?page=${pageParam}`
89-
},
90-
}),
91-
counters: builder.query<{ id: string; counter: number }, string>({
87+
),
88+
counters: build.query<{ id: string; counter: number }, string>({
9289
queryFn: async (arg) => {
9390
if (!(arg in counters)) {
9491
counters[arg] = 0
@@ -486,8 +483,8 @@ describe('Infinite queries', () => {
486483
test('can fetch pages with refetchOnMountOrArgChange active', async () => {
487484
const pokemonApiWithRefetch = createApi({
488485
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
489-
endpoints: (builder) => ({
490-
getInfinitePokemon: builder.infiniteQuery<Pokemon[], string, number>({
486+
endpoints: (build) => ({
487+
getInfinitePokemon: build.infiniteQuery<Pokemon[], string, number>({
491488
infiniteQueryOptions: {
492489
initialPageParam: 0,
493490
getNextPageParam: (

0 commit comments

Comments
 (0)