Skip to content

Commit

Permalink
feat(meta): Passes meta to result description functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bbboydston committed Jan 12, 2022
1 parent 8da122d commit 20fd4d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const build: SubMiddlewareBuilder = ({
undefined,
undefined,
undefined,
undefined,
assertTagType
),
mwApi
Expand Down
1 change: 1 addition & 0 deletions packages/toolkit/src/query/core/buildThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ export function calculateProvidedByThunk(
isFulfilled(action) ? action.payload : undefined,
isRejectedWithValue(action) ? action.payload : undefined,
action.meta.arg.originalArgs,
action.meta,
assertTagType
)
}
29 changes: 20 additions & 9 deletions packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TagDescription<TagTypes>>

export type FullTagDescription<TagType> = {
Expand All @@ -163,10 +165,11 @@ export type ResultDescription<
TagTypes extends string,
ResultType,
QueryArg,
ErrorType
ErrorType,
MetaType
> =
| ReadonlyArray<TagDescription<TagTypes>>
| GetResultDescriptionFn<TagTypes, ResultType, QueryArg, ErrorType>
| GetResultDescriptionFn<TagTypes, ResultType, QueryArg, ErrorType, MetaType>

/** @deprecated please use `onQueryStarted` instead */
export interface QueryApi<ReducerPath extends string, Context extends {}> {
Expand Down Expand Up @@ -236,7 +239,8 @@ export interface QueryExtraOptions<
TagTypes,
ResultType,
QueryArg,
BaseQueryError<BaseQuery>
BaseQueryError<BaseQuery>,
BaseQueryMeta<BaseQuery>
>
/**
* Not to be used. A query should not invalidate tags in the cache.
Expand Down Expand Up @@ -310,7 +314,8 @@ export interface MutationExtraOptions<
TagTypes,
ResultType,
QueryArg,
BaseQueryError<BaseQuery>
BaseQueryError<BaseQuery>,
BaseQueryMeta<BaseQuery>
>
/**
* Not to be used. A mutation should not provide tags to the cache.
Expand Down Expand Up @@ -429,17 +434,23 @@ export type EndpointBuilder<

export type AssertTagTypes = <T extends FullTagDescription<string>>(t: T) => T

export function calculateProvidedBy<ResultType, QueryArg, ErrorType>(
export function calculateProvidedBy<ResultType, QueryArg, ErrorType, MetaType>(
description:
| ResultDescription<string, ResultType, QueryArg, ErrorType>
| ResultDescription<string, ResultType, QueryArg, ErrorType, MetaType>
| undefined,
result: ResultType | undefined,
error: ErrorType | undefined,
queryArg: QueryArg,
meta: MetaType | undefined,
assertTagTypes: AssertTagTypes
): readonly FullTagDescription<string>[] {
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)
}
Expand Down

0 comments on commit 20fd4d8

Please sign in to comment.