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

Pass baseQueryMeta into calculateProvidedBy #1926

Merged
merged 4 commits into from
Jan 21, 2022

Conversation

msutkowski
Copy link
Member

@msutkowski msutkowski commented Jan 15, 2022

Patches the work done in #1910 by ensuring that we're exposing baseQueryMeta aka Request and Response objects... which matches the transformResponse behavior for consistency. I debated on doing a full use case example here, but it seemed like it wouldn't really provide any real value and would be better served in usage docs.

Also note: I didn't update the docs for this as @bever1337 is working on those.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 15, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8a94e05:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration

@github-actions
Copy link

github-actions bot commented Jan 15, 2022

size-limit report 📦

Path Size
1. entry point: @reduxjs/toolkit (cjs.production.min.js) 12.93 KB (0%)
1. entry point: @reduxjs/toolkit (esm.js) 10.79 KB (0%)
1. entry point: @reduxjs/toolkit/query (cjs.production.min.js) 22.6 KB (+0.05% 🔺)
1. entry point: @reduxjs/toolkit/query (esm.js) 18.95 KB (+0.06% 🔺)
1. entry point: @reduxjs/toolkit/query/react (cjs.production.min.js) 24.84 KB (+0.04% 🔺)
1. entry point: @reduxjs/toolkit/query/react (esm.js) 21.64 KB (+0.04% 🔺)
2. entry point: @reduxjs/toolkit (without dependencies) (cjs.production.min.js) 5.71 KB (0%)
2. entry point: @reduxjs/toolkit (without dependencies) (esm.js) 5.67 KB (0%)
2. entry point: @reduxjs/toolkit/query (without dependencies) (cjs.production.min.js) 10.06 KB (+0.11% 🔺)
2. entry point: @reduxjs/toolkit/query (without dependencies) (esm.js) 10.48 KB (+0.12% 🔺)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (cjs.production.min.js) 2.8 KB (0%)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (esm.js) 3.21 KB (0%)
3. createSlice (esm.js) 5.03 KB (0%)
3. createEntityAdapter (esm.js) 6.28 KB (0%)
3. configureStore (esm.js) 5.65 KB (0%)
3. createApi (esm.js) 17.19 KB (+0.05% 🔺)
3. createApi (react) (esm.js) 19.9 KB (+0.05% 🔺)
3. fetchBaseQuery (esm.js) 11.61 KB (0%)
3. setupListeners (esm.js) 10.42 KB (0%)
3. ApiProvider (esm.js) 18.53 KB (+0.05% 🔺)

Comment on lines 512 to 526
const isQuery = (action: CalculatableAction) =>
action.meta.arg.type === 'query'
const isFulfilledQuery = (action: any): action is QueryThunk =>
isQuery(action)
const isFulfilledMutation = (action: any): action is MutationThunk =>
!isQuery(action)

return calculateProvidedBy(
endpointDefinitions[action.meta.arg.endpointName][type],
isFulfilled(action) ? action.payload : undefined,
isRejectedWithValue(action) ? action.payload : undefined,
action.meta.arg.originalArgs,
action.meta,
isAnyOf(isRejected, isFulfilledQuery, isFulfilledMutation)(action)
? action.meta.baseQueryMeta
: undefined,
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if all of this ceremony is really necessary, but it's probably better than (action.meta as any).baseQueryMeta or something like that. Very open to ideas here @phryneas if you have one :)

Copy link
Member

Choose a reason for hiding this comment

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

I think that can be done with less changes - I pushed my suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I need to get a 'ways to narrow types' checklist solidified in my brain.

@msutkowski msutkowski marked this pull request as ready for review January 16, 2022 03:08
@msutkowski msutkowski requested review from phryneas and markerikson and removed request for phryneas January 16, 2022 03:08
@bever1337
Copy link
Contributor

Hey @msutkowski 👋 I just got around to submitting a PR for a docs update, let me know if it's up to snuff.

#1934

Would it be easier for your workflow if we merged my branch to yours instead of master? I haven't looked too closely, so I'm not sure what overlap there is. Thanks!

@msutkowski msutkowski merged commit e7a98eb into master Jan 21, 2022
@msutkowski msutkowski deleted the fix-calculateProvidedBy-baseQueryMeta branch January 21, 2022 15:15
@phryneas
Copy link
Member

phryneas commented Feb 3, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants