Expand description
§Firebase Data Connect
Rust port of the Firebase Data Connect SDK. The module mirrors the modular JS surface so apps can register connectors, execute queries or mutations, and hydrate caches both natively and in WASM builds.
Porting status: 80% [######## ] (details)
§Quick Start Example
use std::sync::Arc;
use firebase_rs_sdk::app::initialize_app;
use firebase_rs_sdk::app::{FirebaseAppSettings, FirebaseOptions};
use firebase_rs_sdk::data_connect::{
connect_data_connect_emulator, execute_query, get_data_connect_service, query_ref, subscribe,
ConnectorConfig, QuerySubscriptionHandlers,
};
use serde_json::json;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let options = FirebaseOptions {
project_id: Some("demo-project".into()),
api_key: Some("demo-key".into()),
..Default::default()
};
let settings = FirebaseAppSettings {
name: Some("demo-app".into()),
..Default::default()
};
let app = initialize_app(options, Some(settings)).await?;
let connector = ConnectorConfig::new("us-central1", "books", "catalog")?;
let service = get_data_connect_service(Some(app.clone()), connector).await?;
// Optional: route to the local emulator during development.
connect_data_connect_emulator(&service, "localhost", Some(9399), false)?;
let query = query_ref(Arc::clone(&service), "ListBooks", json!({"limit": 25}));
let result = execute_query(&query).await?;
println!("{}", result.data);
// Async subscriptions deliver cached data immediately when provided.
let handlers = QuerySubscriptionHandlers::new(Arc::new(|result| {
println!("cache update: {}", result.data);
}));
let _subscription = subscribe(query, handlers, None).await?;
Ok(())
}§References to the Firebase JS SDK
- QuickStart: https://firebase.google.com/docs/data-connect/quickstart?userflow=automatic#web
- API: https://firebase.google.com/docs/reference/js/data-connect.md#data-connect_package
- Github Repo - Module: https://github.com/firebase/firebase-js-sdk/tree/main/packages/data-connect
- Github Repo - API: https://github.com/firebase/firebase-js-sdk/tree/main/packages/firebase/data-connect
§WASM Notes
- The transport layer uses
reqwest’s fetch backend when targetingwasm32-unknown-unknown, so no additional shims are required. subscribeand the query/mutation managers avoidSendbounds when compiling with thewasm-webfeature so callbacks can capture browser-only types.
Structs§
- AppCheck
Headers - Connector
Config - Root connector configuration (location/connector/service) supplied by the user.
- Data
Connect Error - Rich failure type returned by Data Connect operations.
- Data
Connect Operation Failure Response - GraphQL error payload mirrored from the JS SDK.
- Data
Connect Operation Failure Response Error Info - Individual error entry returned by the GraphQL endpoint.
- Data
Connect Options - Fully-qualified options passed to the transport layer once the project ID is known.
- Data
Connect Query Runtime - Owns the cached
QueryManagerfor a service, allowing callers to explicitly control when observer state is created or discarded. - Data
Connect Service - Primary interface for Data Connect operations.
- Mutation
Manager - Mutation
Ref - Strongly typed reference to a mutation operation.
- Mutation
Result - Result returned from
execute_mutation. - OpResult
- Minimal payload cached by the query manager.
- Operation
Ref - Common state for query & mutation references.
- Query
Manager - Tracks outstanding queries, cached payloads, and subscribers.
- Query
Ref - Strongly typed reference to a query operation.
- Query
Result - Result returned from
execute_query. - Query
Subscription Handle - Guard returned when subscribing to a query.
- Query
Subscription Handlers - Observer-style subscription handlers.
- RefInfo
- Serialized reference metadata.
- Rest
Transport - Serialized
Query Snapshot - Serializable reference snapshot (mirrors JS SDK
SerializedRef). - Transport
Options - Host/port/SSL tuple used for emulator connections.
Enums§
- Caller
SdkType - Data
Connect Error Code - Enumerates the canonical error codes surfaced by the Data Connect module.
- Data
Connect Error Path Segment - A single entry in the
patharray from a GraphQL error response. - Data
Source - Indicates where a result originated from.
- Operation
Type - Internal discriminant for refs.
Constants§
- DATA_
CONNECT_ COMPONENT_ NAME - DEFAULT_
DATA_ CONNECT_ HOST - Default production host for the Data Connect REST API.
Traits§
Functions§
- cache_
from_ serialized - Converts a serialized query snapshot (e.g. produced on the server) into an initial cache entry.
- connect_
data_ connect_ emulator - Routes all future requests through the emulator configured by the caller.
- execute_
mutation - Executes the provided mutation reference.
- execute_
query - Executes the provided query reference.
- get_
data_ connect_ service - Retrieves (or initializes) a Data Connect service instance for the supplied connector config.
- internal_
error - Helper for constructing an internal error.
- invalid_
argument - Helper for constructing an invalid argument error.
- mutation_
ref - Constructs a mutation reference for the specified operation name and variables.
- operation_
error - Helper for surfacing partial/GraphQL errors from the backend.
- parse_
transport_ options - Parses the
FIREBASE_DATA_CONNECT_EMULATOR_HOSTenvironment variable payload. - query_
ref - Constructs a query reference for the specified operation name and variables.
- register_
data_ connect_ component - subscribe
- Subscribes to a query reference, optionally hydrating from a serialized snapshot.
- to_
query_ ref - Converts a serialized snapshot back into a live
QueryRefusing the default app. - unauthorized
- Helper for constructing an unauthorized error.
Type Aliases§
- Data
Connect Result - Result alias returned by Data Connect APIs.
- Query
Result Callback