Extend DS tutorial to cover state-mutating requests#8962
Draft
mcmire wants to merge 1 commit into
Draft
Conversation
Requests that change state on the server needs special consideration as
we do not want to cache these types of requests. This part of the
tutorial walks through how to do this and how to test that caching does
not occur.
As usual you can view this locally by running:
yarn workspace @metamask/wallet-framework-docs run start-dev
1f59cdc to
31ba7a2
Compare
mcmire
commented
Jun 1, 2026
| import ordersServiceMethodActionTypes3 from '!!raw-loader!./orders-service-method-action-types.ts'; | ||
| import ordersServiceTest3 from '!!raw-loader!./orders-service.test.ts'; | ||
|
|
||
| # Writing a Data Service, Part 3: Making State-Mutating Requests |
Contributor
Author
There was a problem hiding this comment.
I decided to call these "state-mutating requests" because it sounded better than "non-GET requests". But it's kind of a mouthful. Is there something else we should use?
| Now we'll add a new method. <!-- Note that whereas we used `fetchQuery` to make requests previously, now we'll want to use `createMutation`. --> Note the following: | ||
|
|
||
| - We pass `method` and `body` to the `fetch` function. | ||
| - We pass a `staleTime` of 0 to `fetchQuery`. This instructs TanStack Query not to cache these kinds of requests. |
Contributor
Author
There was a problem hiding this comment.
Besides passing a different method to fetch, passing staleTime: 0 to fetchQuery is basically the only difference between "read-only" requests and "state-mutating" requests. The rest is the same thing.
This prompts two questions:
- Should we introduce a
createMutationmethod toBaseDataServiceso that engineers don't have to passstaleTime: 0? - Should we merge parts 2 and 3 together? (I figured not because part 2 was getting long, but happy to reconsider.)
This file contains hidden or 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
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.
Explanation
Requests that change state on the server needs special consideration as we do not want to cache these types of requests. This part of the tutorial walks through how to do this and how to test that caching does not occur.
To read the docs:
yarn workspace @metamask/wallet-framework-docs run start-devScreenshots
References
https://consensyssoftware.atlassian.net/browse/WPC-1003
Checklist