Skip to content

remove unnecessary fetchBaseQuery defaults #3062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/toolkit/src/query/fetchBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export type FetchBaseQueryMeta = { request: Request; response?: Response }
* @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`.
*
* @param {(this: any, key: string, value: any) => any} jsonReplacer Custom replacer function used when calling `JSON.stringify()`.
*
*
* @param {number} timeout
* A number in milliseconds that represents the maximum time a request can take before timing out.
*/
Expand Down Expand Up @@ -216,9 +216,7 @@ export function fetchBaseQuery({
let meta: FetchBaseQueryMeta | undefined
let {
url,
method = 'GET' as const,
headers = new Headers(baseFetchOptions.headers),
body = undefined,
params = undefined,
responseHandler = 'json' as const,
validateStatus = globalValidateStatus ?? defaultValidateStatus,
Expand All @@ -227,9 +225,7 @@ export function fetchBaseQuery({
} = typeof arg == 'string' ? { url: arg } : arg
let config: RequestInit = {
...baseFetchOptions,
method,
signal,
body,
...rest,
}

Expand All @@ -250,12 +246,12 @@ export function fetchBaseQuery({
Array.isArray(body) ||
typeof body.toJSON === 'function')

if (!config.headers.has('content-type') && isJsonifiable(body)) {
if (!config.headers.has('content-type') && isJsonifiable(config.body)) {
config.headers.set('content-type', jsonContentType)
}

if (isJsonifiable(body) && isJsonContentType(config.headers)) {
config.body = JSON.stringify(body, jsonReplacer)
if (isJsonifiable(config.body) && isJsonContentType(config.headers)) {
config.body = JSON.stringify(config.body, jsonReplacer)
}

if (params) {
Expand Down