Skip to content

Commit 23c00ee

Browse files
committedMar 30, 2025
added skipSchemaValidation flag
1 parent de309e9 commit 23c00ee

File tree

5 files changed

+359
-145
lines changed

5 files changed

+359
-145
lines changed
 

‎packages/toolkit/src/query/core/buildThunks.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ export function buildThunks<
342342
assertTagType,
343343
selectors,
344344
onSchemaFailure,
345+
skipSchemaValidation: globalSkipSchemaValidation,
345346
}: {
346347
baseQuery: BaseQuery
347348
reducerPath: ReducerPath
@@ -351,6 +352,7 @@ export function buildThunks<
351352
assertTagType: AssertTagTypes
352353
selectors: AllSelectors
353354
onSchemaFailure: SchemaFailureHandler | undefined
355+
skipSchemaValidation: boolean | undefined
354356
}) {
355357
type State = RootState<any, string, ReducerPath>
356358

@@ -507,7 +509,8 @@ export function buildThunks<
507509
},
508510
) => {
509511
const endpointDefinition = endpointDefinitions[arg.endpointName]
510-
const { metaSchema } = endpointDefinition
512+
const { metaSchema, skipSchemaValidation = globalSkipSchemaValidation } =
513+
endpointDefinition
511514

512515
try {
513516
let transformResponse = getTransformCallbackForEndpoint(
@@ -573,7 +576,7 @@ export function buildThunks<
573576
const { extraOptions, argSchema, rawResponseSchema, responseSchema } =
574577
endpointDefinition
575578

576-
if (argSchema) {
579+
if (argSchema && !skipSchemaValidation) {
577580
finalQueryArg = await parseWithSchema(
578581
argSchema,
579582
finalQueryArg,
@@ -636,7 +639,7 @@ export function buildThunks<
636639

637640
let { data } = result
638641

639-
if (rawResponseSchema) {
642+
if (rawResponseSchema && !skipSchemaValidation) {
640643
data = await parseWithSchema(
641644
rawResponseSchema,
642645
result.data,
@@ -650,7 +653,7 @@ export function buildThunks<
650653
finalQueryArg,
651654
)
652655

653-
if (responseSchema) {
656+
if (responseSchema && !skipSchemaValidation) {
654657
transformedResponse = await parseWithSchema(
655658
responseSchema,
656659
transformedResponse,
@@ -747,7 +750,7 @@ export function buildThunks<
747750
finalQueryReturnValue = await executeRequest(arg.originalArgs)
748751
}
749752

750-
if (metaSchema && finalQueryReturnValue.meta) {
753+
if (metaSchema && !skipSchemaValidation && finalQueryReturnValue.meta) {
751754
finalQueryReturnValue.meta = await parseWithSchema(
752755
metaSchema,
753756
finalQueryReturnValue.meta,
@@ -776,15 +779,15 @@ export function buildThunks<
776779

777780
let { value, meta } = caughtError
778781

779-
if (rawErrorResponseSchema) {
782+
if (rawErrorResponseSchema && !skipSchemaValidation) {
780783
value = await parseWithSchema(
781784
rawErrorResponseSchema,
782785
value,
783786
'rawErrorResponseSchema',
784787
)
785788
}
786789

787-
if (metaSchema) {
790+
if (metaSchema && !skipSchemaValidation) {
788791
meta = await parseWithSchema(metaSchema, meta, 'metaSchema')
789792
}
790793

@@ -794,7 +797,7 @@ export function buildThunks<
794797
meta,
795798
arg.originalArgs,
796799
)
797-
if (errorResponseSchema) {
800+
if (errorResponseSchema && !skipSchemaValidation) {
798801
transformedErrorResponse = await parseWithSchema(
799802
errorResponseSchema,
800803
transformedErrorResponse,

‎packages/toolkit/src/query/core/module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ export const coreModule = ({
517517
refetchOnReconnect,
518518
invalidationBehavior,
519519
onSchemaFailure,
520+
skipSchemaValidation,
520521
},
521522
context,
522523
) {
@@ -584,6 +585,7 @@ export const coreModule = ({
584585
assertTagType,
585586
selectors,
586587
onSchemaFailure,
588+
skipSchemaValidation,
587589
})
588590

589591
const { reducer, actions: sliceActions } = buildSlice({

‎packages/toolkit/src/query/createApi.ts

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export interface CreateApiOptions<
215215
>
216216

217217
onSchemaFailure?: SchemaFailureHandler
218+
skipSchemaValidation?: boolean
218219
}
219220

220221
export type CreateApi<Modules extends ModuleName> = {

‎packages/toolkit/src/query/endpointDefinitions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export type BaseEndpointDefinition<
236236
structuralSharing?: boolean
237237

238238
onSchemaFailure?: SchemaFailureHandler
239+
skipSchemaValidation?: boolean
239240

240241
/* phantom type */
241242
[resultType]?: ResultType

0 commit comments

Comments
 (0)