Installation¶
Shalom ships a Rust-based CLI for code generation and Dart packages for runtime support. This guide covers the minimal setup for a Flutter app using Shalom's declarative annotation API.
Prerequisites¶
- Rust toolchain (for the CLI)
- Flutter SDK (Shalom's declarative widgets are Flutter-only)
Install the CLI¶
The command installs the shalom binary on your PATH.
Add Dart dependencies¶
Or add them via the Flutter CLI:
package:shalomexposesShalomRuntimeClient, links (HttpLink,WebSocketLink), response types, and cache helpers.package:shalom_flutterexposesShalomProvider/ShalomScope, generated widget base classes, fragment scopes, and the debug panel.package:shalom_annotationsprovides@Query,@Mutation,@Subscription, and@Fragment, which the codegen scans for.
Web setup¶
Shalom's Rust runtime runs as WebAssembly in the browser. Use Flutter's
default JavaScript web build or flutter build web --wasm.
Build the browser module from the Shalom source revision matching your Dart package. From the Shalom repository root, with Task installed, run:
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli --locked --version 0.2.118 -j 2
task build:web OUTPUT=/path/to/your_app/web/pkg
Serve pkg/shalom_ffi.js and pkg/shalom_ffi_bg.wasm relative to the app's
base URL, with the .wasm file served as application/wasm. Flutter copies
web/pkg into the site when you run flutter build web. For a standalone
Dart app, place pkg alongside your deployed HTML entry point.
Call await ShalomRuntimeClient.initFlutterRustBridge() before creating the
client. Use a browser-compatible transport (such as package:http for HTTP or
Shalom's WebSocketPackageTransport for WebSockets). Cross-origin GraphQL
endpoints must allow requests from your app's origin.
Project layout¶
The codegen scans your Dart/Flutter source tree for classes annotated with
@Query / @Mutation / @Subscription / @Fragment. You still need a
GraphQL schema file schema.graphql for validation and type generation. A common layout is:
my_flutter_app/
├── lib/
│ ├── graphql/
│ │ └── schema.graphql # GraphQL schema
│ ├── albums_page.dart # @Query widget
│ ├── album_widget.dart # @Fragment widget
│ └── __graphql__/ # Generated code (auto-created)
├── shalom.yml # Optional config (custom scalars, etc.)
└── pubspec.yaml
Generated files are written next to their source files under a __graphql__
directory (for example lib/__graphql__/albums_page.widget.shalom.dart).
Do not edit files under __graphql__ directly.
optional shalom.yml
The shalom.yml configuration is optional unless you need custom scalars mappings or custom output options.
CLI usage¶
Generate code once:
Watch for changes and re-generate on save:
Both commands scan .graphql schema files and annotated .dart files under
the given path (skipping generated __graphql__ directories).