-
-
Notifications
You must be signed in to change notification settings - Fork 242
refactor(pinia-colada): migrate queries to defineQueryOptions
#2610
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
base: main
Are you sure you want to change the base?
Conversation
|
🦋 Changeset detectedLatest commit: c0ca1c9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@brolnickij is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
defineQueryOptions
defineQueryOptions
@brolnickij hold your horses on this one a bit, #2582 is almost ready and it contains some new concepts |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2610 +/- ##
==========================================
+ Coverage 25.23% 25.39% +0.15%
==========================================
Files 386 387 +1
Lines 37188 37302 +114
Branches 1783 1826 +43
==========================================
+ Hits 9385 9473 +88
- Misses 27790 27816 +26
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
commit: |
@brolnickij merged my big thing, seems there are no conflicts and you just need to re-run the snapshots |
...napi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
...napi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@pinia/colada/fetch/@pinia/colada.gen.ts
Fixed
Show fixed
Hide fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brolnickij the only thing I want to discuss is this point
simplify generated query keys by removing body / headers
Why did you feel this was necessary? It creates an inconsistency with the TanStack Query plugin, too. Could this be something that's configurable?
tl;dr
- Is the query key shape change necessary?
- If yes, can it be configurable? What's the better default and why?
- Whatever the change, let's keep it aligned with the TanStack Query plugin. I don't think there's any reason for these two to deviate?
while testing this PR in an internal project I ran into pretty weird cache behavior in Pinia Colada, and digging into the problem showed that Pinia Colada expects JSON-serializable values this is confirmed in the official docs
also, looking at Pinia Colada source code I found that in src/entry-keys.ts the
the analysis above shows that Pinia Colada has its own behavior, and the way the TanStack Query plugin builds keys just doesnt fit Pinia Colada
yes, definitely, because
i dont think that makes sense, because we would have to guarantee deep normalization of
Pinia Colada builds cache on a "string hash", while TanStack Query apparently uses a different mechanism so yeah, to wrap it up, in this case I wouldnt try to “align” two different tools @posva if you have a chance, please check whether my analysis is correct, thanks in advance! |
Yes, Pinia Colada has a serialization mechanism for keys that is needed for SSR. It also hashes them for a couple of other features. It's not configurable because in the vast majority of cases, keys are strings, numbers and plain objects, so users can manually serialize their keys if they contain anything else. That will ensure that keys are matched during hydration, in server side rendered apps |
@brolnickij How do you ensure the query refetches on body change for example? I'm not so worried about headers in the grand scheme of things, but body is often used for search queries. And how does deduplication work if you now have multiple queries with the same key? Is the expectation that they'd override each other? |
ye, i agree after thinking a bit, removing do you have any ideas on how to make
deduplication is still there, |
My naive assumption would be we want our own serializer for query keys which would handle headers and body. After all, we already do something similar for Fetch requests as an example |
I believe you're familiar with this code https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/bodySerializer.ts |
I'm also happy to merge and release an incomplete version of that would help you move faster |
i suggest finishing this task completely within this PR, without merging it into the main branch, so that the feature is "production ready" |
While you're at it, add yourself as a collaborator to the relevant pages in the documentation please |
@mrlubos whenever you got a moment, could you take a look at my fix? P.S. CI is still red even though everything passes locally (looks like the new snapshot didnt stick on the runner) |
@brolnickij can you try |
@mrlubos hmm, i checked, and all the changes were already pushed there are no unstaged or unpushed snapshots left in the local repository |
I can have a look later! |
u were right |
defineQueryOptions
factory for everyxxxQuery
_JSONValue
(so keys are consistent and type-safe)xxxQuery
- kept only the "canonical usage" examplesopenapi-ts-pinia-colada
serializeQueryKeyValue
instead of embedding rawbody
/query
Close #2597