Skip to content

🧭 GraphQL framework for SeaORM

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

SeaQL/seaography

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Dec 1, 2022
70b1104 Â· Dec 1, 2022
Nov 10, 2022
Dec 1, 2022
Dec 1, 2022
Dec 1, 2022
Dec 1, 2022
Sep 12, 2022
Dec 1, 2022
Dec 1, 2022
Nov 19, 2022
Jun 24, 2022
Sep 12, 2022
Nov 19, 2022
Sep 11, 2022
Dec 1, 2022
Sep 11, 2022
Sep 11, 2022
Nov 19, 2022

Repository files navigation

🧭 A GraphQL framework and code generator for SeaORM

crate docs build status

Seaography

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.

Benefits

  • Quick and easy to get started
  • Generates readable code
  • Extensible project structure
  • Based on popular async libraries: async-graphql and SeaORM

Features

  • Relational query (1-to-1, 1-to-N)
  • Pagination on query's root entity
  • Filter with operators (e.g. gt, lt, eq)
  • Order by any column

(Right now there is no mutation, but it's on our plan!)

Quick start - ready to serve in 3 minutes!

Install

cargo install seaography-cli

MySQL

Setup the sakila sample database.

cd examples/mysql
seaography-cli mysql://user:pw@localhost/sakila seaography-mysql-example .
cargo run

Go to http://localhost:8000/ and try out the following queries:

Fetch films and their actors

{
  film(pagination: { pages: { limit: 10, page: 0 } }, orderBy: { title: ASC }) {
    nodes {
      title
      description
      releaseYear
      filmActor {
        nodes {
          actor {
            firstName
            lastName
          }
        }
      }
    }
  }
}

Fetch store and its employee

{
  store(filters: { storeId: { eq: 1 } }) {
    nodes {
      storeId
      address {
        address
        address2
      }
      staff {
        firstName
        lastName
      }
    }
  }
}

Fetch inactive customers with pagination

{
  customer(
    filters: { active: { eq: 0 } }
    pagination: { pages: { page: 2, limit: 3 } }
  ) {
    nodes {
      customerId
      lastName
      email
    }
    pages
    current
  }
}

The query above using cursor pagination

{
  customer(
    filters: { active: { eq: 0 } }
    pagination: { cursor: { limit: 3, cursor: "Int[3]:271" } }
  ) {
    nodes {
      customerId
      lastName
      email
    }
    pageInfo {
      hasPreviousPage
      hasNextPage
      endCursor
    }
  }
}

Complex query with filters on relations

Find all inactive customers, include their address, and their payments with amount greater than 7 ordered by amount the second result

{
  customer(
    filters: { active: { eq: 0 } }
  ) {
    nodes {
      customerId
      lastName
      email
      address {
        address
      }
      payment(
        filters: { amount: { gt: "7" } }
        orderBy: { amount: ASC }
        pagination: { pages: { limit: 1, page: 1 } }
      ) {
        nodes {
          paymentId
          amount
        }
        pages
        current
        pageInfo {
          hasPreviousPage
          hasNextPage
        }
      }
    }
    pageInfo {
      hasPreviousPage
      hasNextPage
      endCursor
    }
  }
}

Postgres

Setup the sakila sample database.

cd examples/postgres
seaography-cli postgres://user:pw@localhost/sakila seaography-postgres-example .
cargo run

SQLite

cd examples/sqlite
seaography-cli sqlite://sakila.db seaography-sqlite-example .
cargo run

Contribution

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.

Seaography is a community driven project. We welcome you to participate, contribute and together build for Rust's future.