Skip to content

Commit 06b1866

Browse files
author
Christophe Prakash
committed
fetchBaseQuery | Add jsonReplacer param
1 parent 026221a commit 06b1866

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/toolkit/src/query/fetchBaseQuery.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export type FetchBaseQueryArgs = {
132132
* Defaults to `application/json`;
133133
*/
134134
jsonContentType?: string
135+
136+
/**
137+
* Custom replacer function used when calling `JSON.stringify()`;
138+
*/
139+
jsonReplacer?: (this: any, key: string, value: any) => any
135140
} & RequestInit &
136141
Pick<FetchArgs, 'responseHandler' | 'validateStatus' | 'timeout'>
137142

@@ -178,6 +183,8 @@ export type FetchBaseQueryMeta = { request: Request; response?: Response }
178183
*
179184
* @param {string} jsonContentType Used when automatically setting the content-type header for a request with a jsonifiable body that does not have an explicit content-type header. Defaults to `application/json`.
180185
*
186+
* @param {(this: any, key: string, value: any) => any} jsonReplacer Custom replacer function used when calling `JSON.stringify()`.
187+
*
181188
* @param {number} timeout
182189
* A number in milliseconds that represents the maximum time a request can take before timing out.
183190
*/
@@ -188,6 +195,7 @@ export function fetchBaseQuery({
188195
paramsSerializer,
189196
isJsonContentType = defaultIsJsonContentType,
190197
jsonContentType = 'application/json',
198+
jsonReplacer,
191199
timeout: defaultTimeout,
192200
validateStatus: globalValidateStatus,
193201
...baseFetchOptions
@@ -247,7 +255,7 @@ export function fetchBaseQuery({
247255
}
248256

249257
if (isJsonifiable(body) && isJsonContentType(config.headers)) {
250-
config.body = JSON.stringify(body)
258+
config.body = JSON.stringify(body, jsonReplacer)
251259
}
252260

253261
if (params) {

0 commit comments

Comments
 (0)