Skip to main content
Goal: async-graphql + MongoService for document reads/writes without Prisma in the Rust path. Canonical walkthrough: Recipe D (D.11 single-file sample).

Cargo.toml

Resolver shape

After MongoModule::for_root, Arc::new(MongoService) is enough for QueryRoot / MutationRoot—connection state lives in module statics (MongoService is a unit handle).

Curl smoke tests

GraphQL exposes fields in camelCase (display_namedisplayName).

Production GraphQL + Mongo

Authorization at the resolver boundary

Treat Mongo collections like any other datastore: derive tenant_id (or viewer_id) from GraphQL Context (populated by an HTTP guard), and always merge it into filter documents:
Never rely on clients to pass tenant_id without verifying it matches the authenticated principal.

Performance and safety

Writes

Use update_one with $set for partial patches; reserve replace_one for true “overwrite document” semantics. Return modified_count / matched_count so mutations can expose success: Boolean! vs NotFound extensions.
Pair with Recipe B for REST + same BSON types; reuse ProfileDoc everywhere for consistent serialization.