-
Notifications
You must be signed in to change notification settings - Fork 3
Remove @lukemorales/query-key-factory, unblock react-query v5 upgrade
#2040
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
Changes from all commits
e5f675f
762956d
fbe5b60
cafe11e
aafeb79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { QueryOptions } from "@tanstack/react-query" | ||
| import { articlesApi } from "../../clients" | ||
| import type { ArticlesApiArticlesListRequest as ArticleListRequest } from "../../generated/v1" | ||
|
|
||
| const articleKeys = { | ||
| root: ["articles"], | ||
| listRoot: () => [...articleKeys.root, "list"], | ||
| list: (params: ArticleListRequest) => [...articleKeys.listRoot(), params], | ||
| detailRoot: () => [...articleKeys.root, "detail"], | ||
| detail: (id: number) => [...articleKeys.detailRoot(), id], | ||
| } | ||
|
|
||
| const articleQueries = { | ||
| list: (params: ArticleListRequest) => | ||
| ({ | ||
| queryKey: articleKeys.list(params), | ||
| queryFn: () => articlesApi.articlesList(params).then((res) => res.data), | ||
| }) satisfies QueryOptions, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't updated to v5 in this PR, but once we updated to v5 (which should be easy now that |
||
| detail: (id: number) => | ||
| ({ | ||
| queryKey: articleKeys.detail(id), | ||
| queryFn: () => | ||
| articlesApi.articlesRetrieve({ id }).then((res) => res.data), | ||
| }) satisfies QueryOptions, | ||
| } | ||
|
|
||
| export { articleQueries, articleKeys } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { QueryOptions } from "@tanstack/react-query" | ||
| import { channelsApi } from "../../clients" | ||
| import type { ChannelsApiChannelsListRequest as FieldsApiListRequest } from "../../generated/v0" | ||
|
|
||
| const channelKeys = { | ||
| root: ["channel"], | ||
| detailRoot: () => [...channelKeys.root, "detail"], | ||
| detail: (id: number) => [...channelKeys.detailRoot(), id], | ||
| detailByType: (channelType: string, name: string) => [ | ||
| ...channelKeys.detailRoot(), | ||
| channelType, | ||
| name, | ||
| ], | ||
| listRoot: () => [...channelKeys.root, "list"], | ||
| list: (params: FieldsApiListRequest) => [...channelKeys.listRoot(), params], | ||
| countsByType: (channelType: string) => [ | ||
| ...channelKeys.root, | ||
| "counts", | ||
| channelType, | ||
| ], | ||
| } | ||
|
|
||
| const channelQueries = { | ||
| list: (params: FieldsApiListRequest) => | ||
| ({ | ||
| queryKey: channelKeys.list(params), | ||
| queryFn: () => channelsApi.channelsList(params).then((res) => res.data), | ||
| }) satisfies QueryOptions, | ||
| detail: (id: number) => | ||
| ({ | ||
| queryKey: channelKeys.detail(id), | ||
| queryFn: () => | ||
| channelsApi.channelsRetrieve({ id }).then((res) => res.data), | ||
| }) satisfies QueryOptions, | ||
| detailByType: (channelType: string, name: string) => | ||
| ({ | ||
| queryKey: channelKeys.detailByType(channelType, name), | ||
| queryFn: () => { | ||
| return channelsApi | ||
| .channelsTypeRetrieve({ channel_type: channelType, name: name }) | ||
| .then((res) => res.data) | ||
| }, | ||
| }) satisfies QueryOptions, | ||
| countsByType: (channelType: string) => | ||
| ({ | ||
| queryKey: channelKeys.countsByType(channelType), | ||
| queryFn: () => { | ||
| return channelsApi | ||
| .channelsCountsList({ channel_type: channelType }) | ||
| .then((res) => res.data) | ||
| }, | ||
| }) satisfies QueryOptions, | ||
| } | ||
|
|
||
| export { channelQueries, channelKeys } |
Uh oh!
There was an error while loading. Please reload this page.
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.
The structure above (and in other queries files) is based on https://tkdodo.eu/blog/effective-react-query-keys#use-query-key-factories (blog by one of the maintainers).
Still a "key factory", but a little less automated than it was with
@lukemorales/query-key-factory.The main downside is that, in contrast to
@lukemorales/query-key-factory, we are now responsible for ensuring the keys are unique.