Skip to content

Commit f0f8637

Browse files
EskiMojo14markerikson
authored andcommitted
added skipSchemaValidation flag
1 parent 33fd9eb commit f0f8637

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
@@ -333,6 +333,7 @@ export function buildThunks<
333333
assertTagType,
334334
selectors,
335335
onSchemaFailure,
336+
skipSchemaValidation: globalSkipSchemaValidation,
336337
}: {
337338
baseQuery: BaseQuery
338339
reducerPath: ReducerPath
@@ -342,6 +343,7 @@ export function buildThunks<
342343
assertTagType: AssertTagTypes
343344
selectors: AllSelectors
344345
onSchemaFailure: SchemaFailureHandler | undefined
346+
skipSchemaValidation: boolean | undefined
345347
}) {
346348
type State = RootState<any, string, ReducerPath>
347349

@@ -496,7 +498,8 @@ export function buildThunks<
496498
},
497499
) => {
498500
const endpointDefinition = endpointDefinitions[arg.endpointName]
499-
const { metaSchema } = endpointDefinition
501+
const { metaSchema, skipSchemaValidation = globalSkipSchemaValidation } =
502+
endpointDefinition
500503

501504
try {
502505
let transformResponse = getTransformCallbackForEndpoint(
@@ -562,7 +565,7 @@ export function buildThunks<
562565
const { extraOptions, argSchema, rawResponseSchema, responseSchema } =
563566
endpointDefinition
564567

565-
if (argSchema) {
568+
if (argSchema && !skipSchemaValidation) {
566569
finalQueryArg = await parseWithSchema(
567570
argSchema,
568571
finalQueryArg,
@@ -625,7 +628,7 @@ export function buildThunks<
625628

626629
let { data } = result
627630

628-
if (rawResponseSchema) {
631+
if (rawResponseSchema && !skipSchemaValidation) {
629632
data = await parseWithSchema(
630633
rawResponseSchema,
631634
result.data,
@@ -639,7 +642,7 @@ export function buildThunks<
639642
finalQueryArg,
640643
)
641644

642-
if (responseSchema) {
645+
if (responseSchema && !skipSchemaValidation) {
643646
transformedResponse = await parseWithSchema(
644647
responseSchema,
645648
transformedResponse,
@@ -736,7 +739,7 @@ export function buildThunks<
736739
finalQueryReturnValue = await executeRequest(arg.originalArgs)
737740
}
738741

739-
if (metaSchema && finalQueryReturnValue.meta) {
742+
if (metaSchema && !skipSchemaValidation && finalQueryReturnValue.meta) {
740743
finalQueryReturnValue.meta = await parseWithSchema(
741744
metaSchema,
742745
finalQueryReturnValue.meta,
@@ -765,15 +768,15 @@ export function buildThunks<
765768

766769
let { value, meta } = caughtError
767770

768-
if (rawErrorResponseSchema) {
771+
if (rawErrorResponseSchema && !skipSchemaValidation) {
769772
value = await parseWithSchema(
770773
rawErrorResponseSchema,
771774
value,
772775
'rawErrorResponseSchema',
773776
)
774777
}
775778

776-
if (metaSchema) {
779+
if (metaSchema && !skipSchemaValidation) {
777780
meta = await parseWithSchema(metaSchema, meta, 'metaSchema')
778781
}
779782

@@ -783,7 +786,7 @@ export function buildThunks<
783786
meta,
784787
arg.originalArgs,
785788
)
786-
if (errorResponseSchema) {
789+
if (errorResponseSchema && !skipSchemaValidation) {
787790
transformedErrorResponse = await parseWithSchema(
788791
errorResponseSchema,
789792
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)