Skip to content

Add datatag to ConnectQueryKey so queryClient can infer type info #532

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

Merged
merged 9 commits into from
May 20, 2025

Conversation

paul-sachs
Copy link
Collaborator

@paul-sachs paul-sachs commented Apr 29, 2025

By adding DataTag annotations to the ConnectQueryKey, QueryClient methods can now infer the return type when calling things like getQueryData or invalidateQueries.

This is at least a partial alternative to #468 which provides better inference abilities while keeping our api surface smaller. There may still be value down the line with very well defined query client methods but I suspect this change covers 90% of the current use cases.

@paul-sachs
Copy link
Collaborator Author

We have an open question for this change. We can enforce that all ConnectQueryKeys have this type parameter or just make createConnectQueryKey return the tagged type. As it stands, requiring the type tag will be a breaking type change but probably makes sense,

@paul-sachs
Copy link
Collaborator Author

I went with an in-between option, I require a param on ConnectQueryKey but it defaults to DescMessage. This allows people to use ConnectQueryKey without the output param but won't be able to infer the return type

@paul-sachs paul-sachs requested a review from timostamm April 29, 2025 19:12
@paul-sachs paul-sachs changed the title Add datatag to connect key so we can infer type info Add datatag to ConnectQueryKey so we can infer type info May 9, 2025
@paul-sachs paul-sachs changed the title Add datatag to ConnectQueryKey so we can infer type info Add datatag to ConnectQueryKey so queryClient can infer type info May 13, 2025
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Neat!

@paul-sachs paul-sachs requested a review from timostamm May 20, 2025 16:34
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

LGTM!

@paul-sachs paul-sachs merged commit 11be77c into main May 20, 2025
11 checks passed
@paul-sachs paul-sachs deleted the psachs/datatag-experiment branch May 20, 2025 18:19
This was referenced May 20, 2025
paul-sachs added a commit that referenced this pull request May 22, 2025
## What's Changed

* Add datatag to ConnectQueryKey so queryClient can infer type info by
@paul-sachs in #532

## New Contributors
* @guspan-tanadi made their first contribution in
#537

**Full Changelog**:
v2.0.1...v2.1.0

Signed-off-by: Paul Sachs <[email protected]>
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