gpui-query
Async state management for GPUI, modeled after TanStack Query.
GPUI draws everything synchronously on the main thread. That makes async data awkward: you end up hand-rolling loading states, error handling, caching, deduplication, retries, and cancellation. gpui-query handles those pieces.
You write a fetcher. The library manages the lifecycle.
Install
[]
= "0.2.0"
The default feature set includes the client layer. To use the declarative view hooks, enable the hook feature:
[]
= { = "0.2.0", = ["hook"] }
If you only want the core state machine without pulling in GPUI:
[]
= { = "0.2.0", = false, = ["core"] }
Quick start
Set up a QueryClient as a GPUI global when your app starts:
use App;
use QueryClient;
new.run;
Create a query in your view:
use ;
Read the state in render:
Feature layers
The crate is split into four layers, each behind a feature flag:
coreis a serde-only state machine with no framework coupling.QueryResource,MutationResource,CachePolicy,RetryPolicy, andQueryKeylive here. You can use this layer in any Rust project.clientis the default feature. It addsQueryClient, a GPUIGlobalthat owns type-partitioned storage. It handles garbage collection, cache invalidation, observers, and devtools diagnostics.hookprovides the declarative hooks (use_query,use_mutation,use_infinite_query) that wire the client into GPUI views. All hooks return(Entity, Subscription)tuples.persistadds the asyncPersistertrait,QueryClient::persist_with(debounced snapshot saves), the freehydratefunction, and typed (de)serializer registries to restore a warm cache on cold start. A ready-made disk adapter ships in the companiongpui-query-persistcrate.
What you get
- Caching with
NoCache,Ttl, andStaleWhileRevalidatepolicies. - Deduplication of concurrent requests that share a key.
- Retry with configurable exponential backoff.
- Cooperative cancellation through the
QuerySignalpassed to every fetcher. - Garbage collection of idle resources after a configurable TTL.
- Cache invalidation by exact key, prefix, or globally.
- Optimistic updates with rollback support.
- Mutation callbacks for success, error, and settled states.
- Infinite queries for paginated data.
- Error sanitization that strips connection strings, tokens, paths, emails, and hex keys from messages.
- Async persistence through the
Persistertrait (persistfeature); a disk adapter ships in thegpui-query-persistcrate, and HTTP cache-header support ingpui-query-http.
Links
- Website: https://gpui-query.freeoxide.com
- Docs: https://gpui-query.freeoxide.com/docs/
- Source: https://github.com/freeoxide/gpui-query
- GPUI: https://github.com/zed-industries/zed/tree/main/crates/gpui
- TanStack Query: https://tanstack.com/query
Author
hmziqrs
- Website: https://hmziq.rs
- GitHub: https://github.com/hmziqrs
- X: https://x.com/hmziqrs
License
MIT. See the LICENSE file for details.