Skip to content

Commit f165125

Browse files
committed
[Seaography] Docs
1 parent 200fe11 commit f165125

File tree

16 files changed

+1004
-52
lines changed

16 files changed

+1004
-52
lines changed

Blog/blog/2025-10-08-seaography.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ This is of course a speed run, but you can follow the [same steps](https://githu
5252
orderBy: { filmId: ASC }
5353
pagination: { page: { page: 0, limit: 10 } }
5454
# ⬆ cursor based pagination is also supported:
55-
# pagination: { cursor: { limit: 10, cursor: "Int[10]:100" } }
55+
# pagination: { cursor: { limit: 10, cursor: "Int[3]:100" } }
5656
) {
5757
nodes {
5858
filmId

Seaography/docs/01-index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
# Seaography
1+
# Index
22

3-
Comprehensive documentation coming soon, please read https://www.sea-ql.org/blog/2025-10-08-seaography/ for a quick introduction.
3+
## Introduction
4+
5+
## Getting Started
6+
7+
## GraphQL Schema
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Why Seaography
2+
3+
## What is GraphQL
4+
5+
GraphQL, originally open-sourced by Facebook, is both a query language and a runtime for APIs. Instead of exposing multiple endpoints like REST, GraphQL provides a single endpoint where clients can specify the exact fields and relationships they want. This makes responses predictable and shaped exactly like the request.
6+
7+
### Benefits of GraphQL
8+
9+
#### Precise data fetching
10+
11+
Clients avoid over-fetching or under-fetching by requesting only the fields they need.
12+
13+
#### Strongly typed schema
14+
15+
The schema acts as a contract between client and server, improving validation, documentation, and developer experience.
16+
17+
#### Unified data access
18+
19+
GraphQL can aggregate data from multiple sources into one query, reducing round-trips. All API requests go through a single POST endpoint.
20+
21+
## Async-GraphQL
22+
23+
[async-graphql](https://docs.rs/async-graphql/latest/async_graphql/) is a Rust library that implements the GraphQL specification with a asynchronous execution model, strong type safety, and dynamic schema definition. It offers:
24+
25+
#### Concurrent field resolution
26+
27+
If a query requests multiple independent fields, async‑graphql can fetch them in parallel.
28+
29+
#### Complexity & depth limits
30+
31+
Built‑in guards to prevent denial‑of‑service via overly complex queries.
32+
33+
#### Strongly-typed schema
34+
35+
Automatic validation ensures schema and resolvers remain consistent.
36+
37+
## Seaography
38+
39+
Seaography is built on top of async‑graphql, offering a set of derive macros, seamless integration with SeaORM, and advanced query capabilities out of the box.
40+
41+
#### Derive macros & faster builds
42+
43+
Seaography provides a set of derive macros for dynamic schema that mirror those used for static schemas in async‑graphql. This makes defining custom GraphQL endpoints easy but also addresses the problem of slow compilation as schema complexity grows.
44+
45+
#### Seamless SeaORM integration
46+
47+
Seaography integrates directly with SeaORM, adding minimal overhead while offering advanced relational query capabilities.
48+
49+
#### Full‑stack solution
50+
51+
Seaography covers all the needs of building complex applications - from data access, backend API, access control to frontend integration ([SeaORM Pro](https://www.sea-ql.org/sea-orm-pro)).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Introduction",
3+
"collapsed": false
4+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Bootstrap Project
2+
3+
## Install cli tools
4+
5+
First, install our cli tools with `cargo`.
6+
7+
```shell
8+
cargo install sea-orm-cli@^2.0.0-rc
9+
cargo install seaography-cli@^2.0.0-rc
10+
```
11+
12+
## Config database url
13+
14+
Set `DATABASE_URL` in your environment to your database connection.
15+
16+
```sh
17+
export DATABASE_URL=protocol://username:password@localhost/database
18+
```
19+
20+
Here are some tips for database specific options:
21+
22+
#### MySQL
23+
24+
```
25+
mysql://username:password@host/database
26+
```
27+
28+
#### Postgres
29+
30+
Specify a schema
31+
32+
```
33+
postgres://username:password@host/database?currentSchema=my_schema
34+
```
35+
36+
#### SQLite
37+
38+
In memory
39+
40+
```
41+
sqlite::memory:
42+
```
43+
44+
Create file if not exists
45+
46+
```
47+
sqlite://path/to/db.sqlite?mode=rwc
48+
```
49+
50+
Read only
51+
52+
```
53+
sqlite://path/to/db.sqlite?mode=ro
54+
```
55+
56+
## Generate SeaORM Entities
57+
58+
```sh
59+
sea-orm-cli generate entity -o src/entities --seaography
60+
```
61+
62+
You will see something like:
63+
64+
```
65+
Writing src/entities/actor.rs
66+
Writing src/entities/address.rs
67+
Writing src/entities/category.rs
68+
Writing src/entities/city.rs
69+
Writing src/entities/country.rs
70+
Writing src/entities/customer.rs
71+
Writing src/entities/film.rs
72+
Writing src/entities/film_actor.rs
73+
Writing src/entities/film_category.rs
74+
Writing src/entities/inventory.rs
75+
Writing src/entities/language.rs
76+
Writing src/entities/payment.rs
77+
Writing src/entities/rental.rs
78+
Writing src/entities/staff.rs
79+
Writing src/entities/store.rs
80+
Writing src/entities/mod.rs
81+
Writing src/entities/prelude.rs
82+
Writing src/entities/sea_orm_active_enums.rs
83+
... Done.
84+
```
85+
86+
## Generate Seaography Project
87+
88+
```sh
89+
seaography-cli -o . -e src/entities --framework axum my-seaography-project
90+
```
91+
92+
You can choose between `actix`, `poem`, `axum` as the web framework. The generated project will have a crate named `my-seaography-project`.
93+
94+
### CLI options
95+
96+
```sh
97+
🧭 A dynamic GraphQL framework for SeaORM
98+
99+
Usage: seaography-cli [OPTIONS] --entities <ENTITIES> --database-url <DATABASE_URL> <CRATE_NAME>
100+
101+
Arguments:
102+
<CRATE_NAME> Crate name for generated project
103+
104+
Options:
105+
-o, --output-dir <OUTPUT_DIR>
106+
Project output directory [default: ./]
107+
-e, --entities <ENTITIES>
108+
Entities directory
109+
-u, --database-url <DATABASE_URL>
110+
Database URL [env: DATABASE_URL]
111+
-f, --framework <FRAMEWORK>
112+
Which web framework to use [default: poem] [possible values: actix, poem, axum]
113+
--depth-limit <DEPTH_LIMIT>
114+
GraphQL depth limit
115+
--complexity-limit <COMPLEXITY_LIMIT>
116+
GraphQL complexity limit
117+
-h, --help
118+
Print help
119+
-V, --version
120+
Print version
121+
```
122+
123+
## Launch!
124+
125+
```sh
126+
cargo build
127+
```
128+
129+
You should see something like:
130+
131+
```sh
132+
Compiling seaography v2.0.0-rc.2
133+
Compiling seaography-postgres-example v0.1.0 (/Users/chris/seaography/examples/postgres)
134+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 28.24s
135+
```
136+
137+
If the build succeeds, then you can launch it:
138+
139+
```sh
140+
cargo run
141+
```
142+
143+
You should see something like:
144+
145+
```sh
146+
Visit GraphQL Playground at http://localhost:8000
147+
```
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Project Structure
2+
3+
The generated project looks like:
4+
5+
```sh
6+
Cargo.toml
7+
src
8+
├── entities
9+
│ ├── actor.rs
10+
│ ├── address.rs
11+
│ ├── category.rs
12+
│ ├── city.rs
13+
│ ├── country.rs
14+
│ ├── mod.rs
15+
│ ├── prelude.rs
16+
│ ├── sea_orm_active_enums.rs
17+
│ └── ..
18+
├── lib.rs
19+
├── main.rs
20+
└── query_root.rs
21+
```
22+
23+
## Entities
24+
25+
This is the folder containing all SeaORM entities. Each file corresponds to a database table.
26+
27+
### `mod.rs`
28+
29+
This is the module file listing all entities. These two macros `register_entity_modules!` and `register_active_enums!` register these entities to Seaography. If you want to ignore certain tables, you can remove them from this list.
30+
31+
```rust
32+
pub mod prelude;
33+
34+
pub mod actor;
35+
pub mod address;
36+
pub mod category;
37+
pub mod city;
38+
pub mod country;
39+
40+
seaography::register_entity_modules!([
41+
actor,
42+
address,
43+
category,
44+
city,
45+
country,
46+
..
47+
]);
48+
seaography::register_active_enums!([ .. ]);
49+
```
50+
51+
## GraphQL schema
52+
53+
### `query_root.rs`
54+
55+
This is the root of the GraphQL schema.
56+
57+
```rust
58+
lazy_static! {
59+
static ref CONTEXT: BuilderContext = BuilderContext::default();
60+
}
61+
```
62+
63+
The builder context has many config options, and allow you to customize the type mappings of the GraphQL schema. It also allows you to register field guards and lifecycle hooks.
64+
65+
Here it takes all the entities defined in `entities/mod.rs` and register them to Seaography schema builder.
66+
If you added custom input, output or query endpoints, this is where you'd register them dynamically into the schema.
67+
You can also attach custom data to the GraphQL schema.
68+
69+
```rust
70+
pub fn schema_builder(
71+
context: &'static BuilderContext,
72+
database: DatabaseConnection,
73+
depth: Option<usize>,
74+
complexity: Option<usize>,
75+
) -> SchemaBuilder {
76+
let mut builder = Builder::new(context, database.clone());
77+
builder = register_entity_modules(builder);
78+
builder = register_active_enums(builder);
79+
builder
80+
.set_depth_limit(depth)
81+
.set_complexity_limit(complexity)
82+
.schema_builder()
83+
.data(database)
84+
}
85+
```
86+
87+
## App
88+
89+
### `Cargo.toml`
90+
91+
```toml
92+
[dependencies]
93+
sea-orm = { version = "~2.0.0-rc", features = ["sqlx-postgres", "runtime-tokio-native-tls", "seaography"] }
94+
..
95+
96+
[dependencies.seaography]
97+
version = "~2.0.0-rc" # seaography version
98+
features = ["with-decimal", "with-chrono"]
99+
```
100+
101+
`sea-orm` version must match `seaography`'s version. If you're using other database, replace `sqlx-postgres` with `sqlx-mysql` / `sqlx-sqlite`.
102+
103+
There are some useful feature flags for `seaography`:
104+
105+
+ `macros`: derive macros
106+
+ `schema-meta`: additional endpoints for schema metadata
107+
+ `rbac`: RBAC support
108+
+ `field-snake-case`: use snake case instead of camel case for fields
109+
+ `field-pluralize`: pluralize complex fields. i.e. use `posts` instead of `post`
110+
<br/>
111+
112+
+ `with-json`: support JSON as scalar value
113+
+ `with-chrono`: support `chrono` crate
114+
+ `with-time`: support `time` crate
115+
+ `with-uuid`: support `uuid` crate
116+
+ `with-decimal`: support `rust_decimal` crate
117+
+ `with-bigdecimal`: support `bigdecimal` crate
118+
+ `with-postgres-array`: support Postgres' array type
119+
120+
### `main.rs`
121+
122+
This is the entry point to the web app. It setups the routes, i.e. `GET` for GrapQL playground, `POST` for handling GraphQL queries.
123+
124+
You will find a config section:
125+
126+
```rust
127+
lazy_static! {
128+
static ref URL: String = env::var("URL").unwrap_or(..);
129+
static ref ENDPOINT: String = env::var("ENDPOINT").unwrap_or(..);
130+
static ref DATABASE_URL: String = env::var("DATABASE_URL").expect(..);
131+
static ref DEPTH_LIMIT: Option<usize> = ..
132+
static ref COMPLEXITY_LIMIT: Option<usize> = ..
133+
}
134+
```
135+
136+
These are some config options you can override via environment variables, or by `.env`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Getting Started",
3+
"collapsed": false
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Data Types
2+
3+
GraphQL only has these built-in scalar types:
4+
5+
+ `Int`: A signed 32‐bit integer.
6+
+ `Float`: A signed double-precision floating-point value.
7+
+ `String`: A UTF‐8 character sequence.
8+
+ `Boolean`: `true` or `false`.
9+
10+
The SeaORM type system supports a richer set of types, including:
11+
12+
+ `Date`, `Time`, `Datetime`: will be mapped to `String`
13+
+ `Decimal`, `BigDecimal`: will be mapped to `String`
14+
+ `Uuid`: will be mapped to `String`
15+
+ `Json`: will be mapped to a custom scalar type `Json`

0 commit comments

Comments
 (0)