Seaography: A Quick Dive into GraphQL for Rust Backend Development
The Backend for Frontend (BFF) pattern is implemented using the de-facto standard GraphQL, which offers a flexible and efficient mechanism of data fetching. In this blog post, we will discuss the advantages of using GraphQL for backend development and introduce Seaography, a Rust-based GraphQL framework that makes it easier to create a GraphQL server.
Source Code: https://github.com/rajat965ng/bff-graphql-seaography.git
Why Seography for GraphQL?
- Quick and Easy to Get Started: GraphQL helps frontend developers to request only the necessary data, which minimizes such situations as over-fetching and under-fetching of data. Seaography, which has a CLI tool, also simplifies configuring a GraphQL server.
- Readable Code: Seaography creates Rust code that is human-readable from your current database schema. This ensures that the codebase is easily legible and manageable even to developers just joining the project.
- Extensible Project Structure: Seaography adopts a modular project structure that allows for easy extension and customization as your project grows. It is possible to introduce new features or modify existing ones without breaking the entire codebase.
- Based on Popular Async Libraries: Seaography makes use of async-graphql and SeaORM, widely employed libraries in the Rust ecosystem for asynchronous GraphQL execution and database access.
Seaography Features
- Relational Query (1-to-1, 1-to-N): Seaography makes relational queries easy: you can retrieve data with relations without having to think about it.
- Pagination on Query’s Root Entity: It is easy to introduce pagination in Seaography. As for performance, you can fetch a certain number of records at once.
- Filter with Operators (e.g., gt, lt, eq): Seaography provides a range of filter operators, which means that it is possible to refine the results of your query according to certain conditions.
- Order by Any Column: Data sorting is an important part of any application. Seaography allows you to sort your query results by any column, thus allowing for the flexibility of data representation.
Getting Started with Seaography
compose.yml
Seaography CLI Installation
cargo install seaography-cli
Generate GraphQL Code from Existing Database
seaography-cli postgres://postgres:postgres@localhost:5432/employee employee employee
Querying Employee Data
query {
employee {
nodes {
firstName
lastName
gender
}
}
}
Conclusion
Seaography leverages the strength of GraphQL, Rust, and SeaORM to deliver a smooth backend API development. With its simple setup, easy-to-read codebase, and powerful features, Seaography is a reliable option for Rust developers who want to use GraphQL in their projects. Try it out and jump into the realm of productive and scalable GraphQL development with Seaography!