Skip to content
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

feat(meta): Passes meta to result description functions [#1904] #1910

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
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
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,
Copy link
Member

@phryneas phryneas Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for chiming in late, but I'm like 80% sure that this is the "wrong meta".

I'm pretty sure this would need to be action.meta.baseQueryMeta.

Can you please verify this?

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