Module data_connect

Module data_connect 

Source
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

§WASM Notes

  • The transport layer uses reqwest’s fetch backend when targeting wasm32-unknown-unknown, so no additional shims are required.
  • subscribe and the query/mutation managers avoid Send bounds when compiling with the wasm-web feature so callbacks can capture browser-only types.

Structs§

AppCheckHeaders
ConnectorConfig
Root connector configuration (location/connector/service) supplied by the user.
DataConnectError
Rich failure type returned by Data Connect operations.
DataConnectOperationFailureResponse
GraphQL error payload mirrored from the JS SDK.
DataConnectOperationFailureResponseErrorInfo
Individual error entry returned by the GraphQL endpoint.
DataConnectOptions
Fully-qualified options passed to the transport layer once the project ID is known.
DataConnectQueryRuntime
Owns the cached QueryManager for a service, allowing callers to explicitly control when observer state is created or discarded.
DataConnectService
Primary interface for Data Connect operations.
MutationManager
MutationRef
Strongly typed reference to a mutation operation.
MutationResult
Result returned from execute_mutation.
OpResult
Minimal payload cached by the query manager.
OperationRef
Common state for query & mutation references.
QueryManager
Tracks outstanding queries, cached payloads, and subscribers.
QueryRef
Strongly typed reference to a query operation.
QueryResult
Result returned from execute_query.
QuerySubscriptionHandle
Guard returned when subscribing to a query.
QuerySubscriptionHandlers
Observer-style subscription handlers.
RefInfo
Serialized reference metadata.
RestTransport
SerializedQuerySnapshot
Serializable reference snapshot (mirrors JS SDK SerializedRef).
TransportOptions
Host/port/SSL tuple used for emulator connections.

Enums§

CallerSdkType
DataConnectErrorCode
Enumerates the canonical error codes surfaced by the Data Connect module.
DataConnectErrorPathSegment
A single entry in the path array from a GraphQL error response.
DataSource
Indicates where a result originated from.
OperationType
Internal discriminant for refs.

Constants§

DATA_CONNECT_COMPONENT_NAME
DEFAULT_DATA_CONNECT_HOST
Default production host for the Data Connect REST API.

Traits§

DataConnectTransport
RequestTokenProvider

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_HOST environment 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 QueryRef using the default app.
unauthorized
Helper for constructing an unauthorized error.

Type Aliases§

DataConnectResult
Result alias returned by Data Connect APIs.
QueryResultCallback