Skip to main content

API Reference

A compact index of the public surface, grouped by the crate's three layers. Import hooks and common types from the crate root; import layer-specific items from gpui_query::core, gpui_query::client, or gpui_query::hook.

// Hooks and common types at the crate root:
use gpui_query::{
use_query, use_mutation, use_infinite_query, use_query_select,
QueryOptions, InfiniteQueryOptions, MutationOptions, MutationCallbacks,
QueryKey, QueryKeyFilter, QueryError, QueryErrorKind, QueryStatus,
CachePolicy, RequestPolicy, RetryPolicy, QueryClient,
};

core — Serde-only state machine

The core layer has no GPUI dependency. Everything here is Serialize + Deserialize (unless noted) and safe to persist.

Keys and filters

ItemKindNotes
QueryKeystructHierarchical cache key, Arc<[Arc<str>]>-backed.
QueryKeyFilterenumExact(&k) / Prefix(&k) / All. Used by bulk ops.

Policies and status

ItemKindNotes
CachePolicyenumNoCache / Ttl { ttl_ms } / StaleWhileRevalidate { ttl_ms, stale_ms }.
RequestPolicyenumLatestWins (default) / IgnoreWhileLoading.
RetryPolicystructmax_retries, retry_delay_ms, exponential_backoff, max_retry_delay_ms.
QueryStatusenumIdle / LoadingEmpty / LoadingWithData / Success / Failure / Cancelled.
MutationStatusenumIdle / Loading / Success / Failure.
QueryFetchModeenumNormal / Force.
QueryBeginResultenumStarted / CacheHit / StaleCacheHit / IgnoredWhileLoading.
RequestIdstructMonotonic per-resource request id.
QuerySignalstructCooperative-cancellation signal handed to fetchers.

Errors

ItemKindNotes
QueryErrorstructDefault error type. Display + Error, Arc<str> message. Constructors: response / transport / cancelled / unknown / sanitized.
QueryErrorKindenumCancelled / Response / Transport / Unknown.

Resources

ItemKindNotes
QueryResource<T, E>structThe core cached resource. Accessors: data, error, status, key, cache_policy, retry_count, last_updated_at_ms, …
MutationResource<V,T,E>structOne mutation's lifecycle.
InfiniteQueryResource<T,E>structPages + pagination state. pages, page_count, has_next_page, is_fetching_next_page, …
SelectTransform<T, U>structFn(&T) -> U wrapper for derived views.
MappedQueryResource<T,U,E>structA derived view applying a SelectTransform.

client — GPUI registry

ItemKindNotes
QueryClientstructGlobal registry. resource, query, get_query_data, set_query_data, with_query_data, invalidate_queries, cancel_queries, reset_queries, remove_queries, prepare_fetch_query, prepare_prefetch_query, gc, gc_with_time, diagnostics, dehydrate, hydrate, persist, restore.
Observer<R>structGeneric status-deduplicating observer.
QueryObserver<T,E>aliasObserver<QueryResource<T, E>>.
InfiniteQueryObserver<T,E>aliasObserver<InfiniteQueryResource<T, E>>.
MutationObserver<V,T,E>aliasObserver<MutationResource<V, T, E>>.
ObserverConfigstructnotify_on_status_change_only (default true).
QueryPersistertraitload() -> Vec<DehydratedEntry>, save(Vec<DehydratedEntry>).
PreparedFetch<T,E>structImperative fetch handle: entity, signal, request_id, now_ms.
QueryDiagnostic / MutationDiagnostic / ClientDiagnosticstructsDevTools snapshot types.
DehydratedState / DehydratedEntrystructsCache snapshot for persistence.

hook — Ergonomic subscriptions

All hooks return (Entity<Resource>, Subscription) (or a triple for use_query_select). Store both.

ItemReturnsNotes
use_query(Entity<QueryResource<T,E>>, Subscription)Primary query hook, signal-always.
use_query_manual / _optssameLower-level: explicit params.
use_query_unsignalled / _optssameFetcher takes no signal (legacy).
use_query_select(Entity<MappedQueryResource<T,U,E>>, Entity<QueryResource<T,E>>, (Subscription, Subscription))select pattern.
use_infinite_query(Entity<InfiniteQueryResource<T,E>>, Subscription)Pagination / load-more.
fetch_next_page_infinite()Grow an infinite query forward.
fetch_previous_page_infinite()Grow an infinite query backward.
fetch_query / fetch_query_with_signal()Refetch on demand.
use_mutation(Entity<MutationResource<V,T,E>>, Subscription)Primary mutation hook.
use_mutation_stateVec<Entity<MutationResource<V,T,E>>>All mutations of a type triple.
mutate()Trigger with owned V.
mutate_with_callbacks()Trigger + lifecycle callbacks.
mutate_by_ref()Trigger, mutator borrows &V.
mutate_arc()Trigger with shared Arc<V>.

Feature flags

The three layers are gated behind feature flags so you can compile only what you need:

FlagEnables
coreThe Serde-only state machine (no GPUI dep).
clientQueryClient, observers, persister, devtools.
hookuse_query / use_mutation / use_infinite_query and friends.

docsrs enables #[doc(cfg(...))] gating on docs.rs builds so the rendered API docs annotate each item with its feature gate.

Next steps

  • The detailed pages in the sidebar cover each of these in depth — start with Queries.
  • For the full item-level documentation, build the Rust API docs with cargo doc -p gpui-query --open.