Seaography: A Quick Dive into GraphQL for Rust Backend Development

Rajat Nigam
Dev Genius
Published in
3 min readJan 22, 2024

--

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

Things Only An Indian 90s School Kid Will Relate To & Terribly Miss. Ever got caught with those trump card packs in school? Lol! | Source: https://www.whatshot.in/delhi-ncr/throwback-things-only-an-indian-90s-school-kid-will-relate-to-terribly-miss-c-24255

Why Seography for GraphQL?

  1. 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.
  2. 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.
  3. 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.
  4. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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

Setup Postgres db instance and initialise employee database

Seaography CLI Installation

cargo install seaography-cli

Generate GraphQL Code from Existing Database

seaography-cli postgres://postgres:postgres@localhost:5432/employee employee employee
output — /employee
cd employee && cargo run .

Querying Employee Data

query {
employee {
nodes {
firstName
lastName
gender
}
}
}
http://localhost:8000

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!

--

--

I'm a lifetime student of software engineering. Professionally I work in the capacity of Individual Contributor, Trainer, Lead Engineer and an Architect.