1
1
import type { Api , ApiContext , Module , ModuleName } from './apiTypes'
2
2
import type { CombinedState } from './core/apiState'
3
3
import type { BaseQueryArg , BaseQueryFn } from './baseQueryTypes'
4
- import type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
5
- import { buildSerializeQueryArgs } from './buildSerializeQueryArgs'
4
+ import {
5
+ defaultSerializeQueryArgs ,
6
+ SerializeQueryArgs ,
7
+ } from './defaultSerializeQueryArgs'
6
8
import type {
7
9
EndpointBuilder ,
8
10
EndpointDefinitions ,
@@ -236,18 +238,25 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
236
238
} )
237
239
)
238
240
239
- const { serializeQueryArgs, registerArgsSerializerForEndpoint } =
240
- buildSerializeQueryArgs ( options . serializeQueryArgs )
241
-
242
- const optionsWithDefaults = {
241
+ const optionsWithDefaults : CreateApiOptions < any , any , any , any > = {
243
242
reducerPath : 'api' ,
244
243
keepUnusedDataFor : 60 ,
245
244
refetchOnMountOrArgChange : false ,
246
245
refetchOnFocus : false ,
247
246
refetchOnReconnect : false ,
248
247
...options ,
249
248
extractRehydrationInfo,
250
- serializeQueryArgs,
249
+ serializeQueryArgs ( queryArgsApi ) {
250
+ let finalSerializeQueryArgs = defaultSerializeQueryArgs
251
+ if ( 'serializeQueryArgs' in queryArgsApi . endpointDefinition ) {
252
+ finalSerializeQueryArgs =
253
+ queryArgsApi . endpointDefinition . serializeQueryArgs !
254
+ } else if ( options . serializeQueryArgs ) {
255
+ finalSerializeQueryArgs = options . serializeQueryArgs
256
+ }
257
+
258
+ return finalSerializeQueryArgs ( queryArgsApi )
259
+ } ,
251
260
tagTypes : [ ...( options . tagTypes || [ ] ) ] ,
252
261
}
253
262
@@ -269,8 +278,8 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
269
278
enhanceEndpoints ( { addTagTypes, endpoints } ) {
270
279
if ( addTagTypes ) {
271
280
for ( const eT of addTagTypes ) {
272
- if ( ! optionsWithDefaults . tagTypes . includes ( eT as any ) ) {
273
- optionsWithDefaults . tagTypes . push ( eT as any )
281
+ if ( ! optionsWithDefaults . tagTypes ! . includes ( eT as any ) ) {
282
+ ; ( optionsWithDefaults . tagTypes as any [ ] ) . push ( eT )
274
283
}
275
284
}
276
285
}
@@ -293,7 +302,7 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
293
302
} as Api < BaseQueryFn , { } , string , string , Modules [ number ] [ 'name' ] >
294
303
295
304
const initializedModules = modules . map ( ( m ) =>
296
- m . init ( api as any , optionsWithDefaults , context )
305
+ m . init ( api as any , optionsWithDefaults as any , context )
297
306
)
298
307
299
308
function injectEndpoints (
@@ -323,13 +332,6 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
323
332
continue
324
333
}
325
334
326
- if ( isQueryDefinition ( definition ) && definition . serializeQueryArgs ) {
327
- registerArgsSerializerForEndpoint (
328
- endpointName ,
329
- definition . serializeQueryArgs
330
- )
331
- }
332
-
333
335
context . endpointDefinitions [ endpointName ] = definition
334
336
for ( const m of initializedModules ) {
335
337
m . injectEndpoint ( endpointName , definition )
0 commit comments