From 20fd4d8f2abdb662af7ecc9de5fd382ae5bd3719 Mon Sep 17 00:00:00 2001 From: Beverly Boydston Date: Tue, 11 Jan 2022 20:28:05 -0500 Subject: [PATCH] feat(meta): Passes meta to result description functions --- .../buildMiddleware/invalidationByTags.ts | 1 + .../toolkit/src/query/core/buildThunks.ts | 1 + .../toolkit/src/query/endpointDefinitions.ts | 29 +++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts b/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts index b84bfb5624..ba1dc6f77b 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts @@ -47,6 +47,7 @@ export const build: SubMiddlewareBuilder = ({ undefined, undefined, undefined, + undefined, assertTagType ), mwApi diff --git a/packages/toolkit/src/query/core/buildThunks.ts b/packages/toolkit/src/query/core/buildThunks.ts index 8c3ccbd1ba..58496877aa 100644 --- a/packages/toolkit/src/query/core/buildThunks.ts +++ b/packages/toolkit/src/query/core/buildThunks.ts @@ -513,6 +513,7 @@ export function calculateProvidedByThunk( isFulfilled(action) ? action.payload : undefined, isRejectedWithValue(action) ? action.payload : undefined, action.meta.arg.originalArgs, + action.meta, assertTagType ) } diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index dfaa2a0818..dc8ccc87c0 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -147,11 +147,13 @@ export type GetResultDescriptionFn< TagTypes extends string, ResultType, QueryArg, - ErrorType + ErrorType, + MetaType > = ( result: ResultType | undefined, error: ErrorType | undefined, - arg: QueryArg + arg: QueryArg, + meta: MetaType ) => ReadonlyArray> export type FullTagDescription = { @@ -163,10 +165,11 @@ export type ResultDescription< TagTypes extends string, ResultType, QueryArg, - ErrorType + ErrorType, + MetaType > = | ReadonlyArray> - | GetResultDescriptionFn + | GetResultDescriptionFn /** @deprecated please use `onQueryStarted` instead */ export interface QueryApi { @@ -236,7 +239,8 @@ export interface QueryExtraOptions< TagTypes, ResultType, QueryArg, - BaseQueryError + BaseQueryError, + BaseQueryMeta > /** * Not to be used. A query should not invalidate tags in the cache. @@ -310,7 +314,8 @@ export interface MutationExtraOptions< TagTypes, ResultType, QueryArg, - BaseQueryError + BaseQueryError, + BaseQueryMeta > /** * Not to be used. A mutation should not provide tags to the cache. @@ -429,17 +434,23 @@ export type EndpointBuilder< export type AssertTagTypes = >(t: T) => T -export function calculateProvidedBy( +export function calculateProvidedBy( description: - | ResultDescription + | ResultDescription | undefined, result: ResultType | undefined, error: ErrorType | undefined, queryArg: QueryArg, + meta: MetaType | undefined, assertTagTypes: AssertTagTypes ): readonly FullTagDescription[] { if (isFunction(description)) { - return description(result as ResultType, error as undefined, queryArg) + return description( + result as ResultType, + error as undefined, + queryArg, + meta as MetaType + ) .map(expandTagDescription) .map(assertTagTypes) }