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

fix(react-query): add query params to query key #87

Merged
merged 2 commits into from
Jan 21, 2025
Merged

Conversation

cjquines
Copy link
Member

the query key should contain all the dependencies of the query, so it should also include the query params

@cjquines cjquines requested a review from matt-casey January 21, 2025 20:35
@@ -122,7 +122,7 @@ describe("Generated API Client", () => {
it("can pass query params", async () => {
const { queryFn, queryKey } = client.cats.useList({ color: "black" });

expect(queryKey).toEqual(["/api/cats"]);
expect(queryKey).toEqual(["/api/cats?color=black"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I could picture the query key being an array to make invalidation easier to do piecemeal, but that would be when stl-api reaches a more mature state

Suggested change
expect(queryKey).toEqual(["/api/cats?color=black"]);
expect(queryKey).toEqual(["/api/cats", "color=black"]);

Copy link
Member Author

Choose a reason for hiding this comment

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

ideally our query keys would be hierarchical (see tkdoko's recs)

so that e.g. client.cats.getQueryKey() would be the key that invalidates everything under client.cats

but yes, that would be for later...

Copy link
Member Author

Choose a reason for hiding this comment

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

we can probably split this array, at least

@cjquines cjquines merged commit d372e71 into main Jan 21, 2025
1 check failed
@cjquines cjquines deleted the cj/query-key-query branch January 21, 2025 21:03
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.

2 participants