-
Notifications
You must be signed in to change notification settings - Fork 4
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
[WIP] refactor: Transition from useAsync
to RTK Query (M2-8618)
#2021
Draft
farmerpaul
wants to merge
13
commits into
develop
Choose a base branch
from
refactor/rtk-query
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+769
−714
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request is automatically being deployed by Amplify Hosting (learn more). |
b48056d
to
16e2214
Compare
Piggypacking on auth token derived from existing axios auth logic.
`ParticipantsData` and `ManagersData` representing API response data had been previously defined within component definitions rather than `api.types.ts`. Removed these in favour of the api-defined types.
Async thunks that make API calls can't be converted to RTK Query due to circular dependencies that introduces in unit tests. The correct solution is to actually do away with some async thunks altogether, as their role in most cases has been replaced by RTK Query.
Add `jest-fetch-mock` to support mocking HTTP GET requests that use `fetch` to support RTK Query. Update `mockGetRequestResponses` utility to seamlessly support both Axios and `fetch`-based HTTP requests. Update unit tests to use appropriate mocks for `fetch`-based requests.
Create RTK Query adapter to use Axios instead of `fetch`, allowing us to reuse more existing auth and API infrastructure. This also allowed reverting patches to unit tests and the `httpMocks` utility, which were previously needed only because we had to support both Axios and `fetch`.
16e2214
to
eb9dade
Compare
useAsync
to RTK Query (M2-8618)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Description
Important
This is not quite ready for official review. I have a couple small tweaks left to add and plan to organize the commits more logically. Stay tuned!
🔗 Jira Ticket M2-8618
This PR begins the migration from
useAsync
and raw Axios mutation functions to RTK Query, which has been agreed upon as the new paradigm for making API calls in the Admin App.See this Confluence doc for context:
In this PR, these endpoints have (mostly) been migrated over to RTK Query:
activities/applet/${appletId}
workspaces/${ownerId}/managers
workspaces/${ownerId}/applets/${appletId}/managers
workspaces/${ownerId}/respondents
1workspaces/${ownerId}/applets/${appletId}/respondents
1invitations/${appletId}/${url}
invitations/${appletId}/subject
invitations/${appletId}/shell-account
subjects/${subjectId}
subjects/${subjectId}
Note
1 For now, preserved
getWorkspaceRespondentsApi
(which also calls these endpoints), as it is used in an async thunk. This and similar thunks should be deprecated, as they needlessly duplicate core RTK Query functionality.As well, a custom base query function,
axiosBaseQuery
, has been written, allowing RTK Query to useaxios
instead offetch
for its HTTP requests (which it uses by default). Continuing to useaxios
for network requests allows unit tests to remain mostly unaffected by the migrated endpoints (preserving the use ofjest-mock-axios
), as well as the existing authentication stack to be used with no changes needed.