seaography/
lib.rs

1//! <div align="center">
2//!
3//!   <img src="https://raw.githubusercontent.com/SeaQL/seaography/main/docs/Seaography.png" width="280" alt="Seaography logo"/>
4//!
5//!   <p>
6//!     <strong>🧭 A GraphQL framework and code generator for SeaORM</strong>
7//!   </p>
8//!
9//!   [![crate](https://img.shields.io/crates/v/seaography.svg)](https://crates.io/crates/seaography)
10//!   [![docs](https://docs.rs/seaography/badge.svg)](https://docs.rs/seaography)
11//!   [![build status](https://github.com/SeaQL/seaography/actions/workflows/tests.yaml/badge.svg)](https://github.com/SeaQL/seaography/actions/workflows/tests.yaml)
12//!
13//! </div>
14//!
15//! # Seaography
16//!
17//! #### Seaography is a GraphQL framework for building GraphQL resolvers using SeaORM entities. It ships with a CLI tool that can generate ready-to-compile Rust GraphQL servers from existing MySQL, Postgres and SQLite databases.
18//!
19//! ## Benefits
20//!
21//! * Quick and easy to get started
22//! * Generates readable code
23//! * Extensible project structure
24//! * Based on popular async libraries: [async-graphql](https://github.com/async-graphql/async-graphql) and [SeaORM](https://github.com/SeaQL/sea-orm)
25//!
26//! ## Features
27//!
28//! * Relational query (1-to-1, 1-to-N)
29//! * Pagination for queries and relations (1-N)
30//! * Filtering with operators (e.g. gt, lt, eq)
31//! * Order by any column
32//! * Guard fields, queries or relations
33//! * Rename fields
34//! * Mutations (create, update, delete)
35//!
36//! (Right now there is no mutation, but it's on our plan!)
37//!
38//! ## SeaORM Version Compatibility
39//!
40//! |                        Seaography                        |                         SeaORM                        |
41//! |----------------------------------------------------------|-------------------------------------------------------|
42//! | [1.1](https://crates.io/crates/seaography/1.1.1)         | [1.1](https://crates.io/crates/sea-orm/1.1.2)         |
43//! | [1.0](https://crates.io/crates/seaography/1.0.0)         | [1.0](https://crates.io/crates/sea-orm/1.0.0)         |
44//! | [0.12](https://crates.io/crates/seaography/0.12.0)       | [0.12](https://crates.io/crates/sea-orm/0.12.14)      |
45//! | [0.3](https://crates.io/crates/seaography/0.3.0)         | [0.10](https://crates.io/crates/sea-orm/0.10.7)       |
46//!
47//! ## Quick start - ready to serve in 3 minutes!
48//!
49//! ### Install
50//!
51//! ```sh
52//! cargo install sea-orm-cli@^1.0.0 # used to generate entities
53//! cargo install seaography-cli@^1.0.0
54//! ```
55//!
56//! ### MySQL
57//!
58//! Setup the [sakila](https://github.com/SeaQL/seaography/blob/main/examples/mysql/sakila-schema.sql) sample database.
59//!
60//! ```sh
61//! cd examples/mysql
62//! sea-orm-cli generate entity -o src/entities -u mysql://user:pw@127.0.0.1/sakila --seaography
63//! seaography-cli ./ src/entities mysql://user:pw@127.0.0.1/sakila seaography-mysql-example
64//! cargo run
65//! ```
66//!
67//! Go to http://localhost:8000/ and try out the following queries:
68//!
69//! #### Fetch films and their actors
70//!
71//! ```graphql
72//! {
73//!   film(pagination: { page: { limit: 10, page: 0 } }, orderBy: { title: ASC }) {
74//!     nodes {
75//!       title
76//!       description
77//!       releaseYear
78//!       actor {
79//!         nodes {
80//!           firstName
81//!           lastName
82//!         }
83//!       }
84//!     }
85//!   }
86//! }
87//! ```
88//!
89//! #### Fetch store and its employee
90//!
91//! ```graphql
92//! {
93//!   store(filters: { storeId: { eq: 1 } }) {
94//!     nodes {
95//!       storeId
96//!       address {
97//!         address
98//!         address2
99//!       }
100//!       staff {
101//!         firstName
102//!         lastName
103//!       }
104//!     }
105//!   }
106//! }
107//! ```
108//!
109//! ### Fetch inactive customers with pagination
110//!
111//! ```graphql
112//! {
113//!   customer(
114//!     filters: { active: { eq: 0 } }
115//!     pagination: { page: { page: 2, limit: 3 } }
116//!   ) {
117//!     nodes {
118//!       customerId
119//!       lastName
120//!       email
121//!     }
122//!     paginationInfo {
123//!       pages
124//!       current
125//!     }
126//!   }
127//! }
128//! ```
129//!
130//! ### The query above using cursor pagination
131//!
132//! ```graphql
133//! {
134//!   customer(
135//!     filters: { active: { eq: 0 } }
136//!     pagination: { cursor: { limit: 3, cursor: "Int[3]:271" } }
137//!   ) {
138//!     nodes {
139//!       customerId
140//!       lastName
141//!       email
142//!     }
143//!     pageInfo {
144//!       hasPreviousPage
145//!       hasNextPage
146//!       endCursor
147//!     }
148//!   }
149//! }
150//! ```
151//!
152//! ### Complex query with filters on relations
153//!
154//! Find all inactive customers, include their address, and their payments with amount greater than 7 ordered by amount the second result
155//!
156//! ```graphql
157//! {
158//!   customer(
159//!     filters: { active: { eq: 0 } }
160//!     pagination: { cursor: { limit: 3, cursor: "Int[3]:271" } }
161//!   ) {
162//!     nodes {
163//!       customerId
164//!       lastName
165//!       email
166//!       address {
167//!         address
168//!       }
169//!       payment(
170//!         filters: { amount: { gt: "7" } }
171//!         orderBy: { amount: ASC }
172//!         pagination: { page: { limit: 1, page: 1 } }
173//!       ) {
174//!         nodes {
175//!           paymentId
176//!           amount
177//!         }
178//!         paginationInfo {
179//!           pages
180//!           current
181//!         }
182//!         pageInfo {
183//!           hasPreviousPage
184//!           hasNextPage
185//!         }
186//!       }
187//!     }
188//!     pageInfo {
189//!       hasPreviousPage
190//!       hasNextPage
191//!       endCursor
192//!     }
193//!   }
194//! }
195//! ```
196//!
197//! ### Filter using enumeration
198//! ```graphql
199//! {
200//!   film(
201//!     filters: { rating: { eq: NC17 } }
202//!     pagination: { page: { page: 1, limit: 5 } }
203//!   ) {
204//!     nodes {
205//!       filmId
206//!       rating
207//!     }
208//!   }
209//! }
210//! ```
211//!
212//! ### Postgres
213//!
214//! Setup the [sakila](https://github.com/SeaQL/seaography/blob/main/examples/postgres/sakila-schema.sql) sample database.
215//!
216//! ```sh
217//! cd examples/postgres
218//! sea-orm-cli generate entity -o src/entities -u postgres://user:pw@localhost/sakila --seaography
219//! seaography-cli ./ src/entities postgres://user:pw@localhost/sakila seaography-postgres-example
220//! cargo run
221//! ```
222//!
223//! ### SQLite
224//!
225//! ```sh
226//! cd examples/sqlite
227//! sea-orm-cli generate entity -o src/entities -u sqlite://sakila.db --seaography
228//! seaography-cli ./ src/entities sqlite://sakila.db seaography-sqlite-example
229//! cargo run
230//! ```
231//!
232//! ## Contribution
233//!
234//! Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
235//!
236//! Seaography is a community driven project. We welcome you to participate, contribute and together build for Rust's future.
237
238pub use heck;
239pub use itertools;
240
241pub mod inputs;
242pub use inputs::*;
243
244pub mod outputs;
245pub use outputs::*;
246
247pub mod enumerations;
248pub use enumerations::*;
249
250pub mod utilities;
251pub use utilities::*;
252
253pub mod query;
254pub use query::*;
255
256pub mod mutation;
257pub use mutation::*;
258
259pub mod builder_context;
260pub use builder_context::*;
261
262pub mod builder;
263pub use builder::*;
264
265pub mod error;
266pub use error::*;
267
268pub type SimpleNamingFn = Box<dyn Fn(&str) -> String + Sync + Send>;
269pub type ComplexNamingFn = Box<dyn Fn(&str, &str) -> String + Sync + Send>;
270
271pub use async_graphql;
272pub use lazy_static;