Skip to content

Commit

Permalink
Update tests and postgres example
Browse files Browse the repository at this point in the history
  • Loading branch information
karatakis committed Oct 4, 2022
1 parent 7f54c02 commit 8b7049b
Show file tree
Hide file tree
Showing 26 changed files with 1,675 additions and 74 deletions.
231 changes: 231 additions & 0 deletions examples/mysql/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,234 @@ async fn test_complex_filter_with_pagination() {
"#,
)
}

#[tokio::test]
async fn test_cursor_pagination() {
let schema = get_schema().await;

assert_eq(
schema
.execute(
r#"
{
paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 5}) {
edges {
node {
paymentId
amount
customer {
firstName
}
}
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
}
}
"#,
)
.await,
r#"
{
"paymentCursor": {
"edges": [
{
"node": {
"paymentId": 342,
"amount": "11.99",
"customer": {
"firstName": "KAREN"
}
}
},
{
"node": {
"paymentId": 3146,
"amount": "11.99",
"customer": {
"firstName": "VICTORIA"
}
}
},
{
"node": {
"paymentId": 5280,
"amount": "11.99",
"customer": {
"firstName": "VANESSA"
}
}
},
{
"node": {
"paymentId": 5281,
"amount": "11.99",
"customer": {
"firstName": "ALMA"
}
}
},
{
"node": {
"paymentId": 5550,
"amount": "11.99",
"customer": {
"firstName": "ROSEMARY"
}
}
}
],
"pageInfo": {
"hasPreviousPage": false,
"hasNextPage": true,
"startCursor": "SmallUnsigned[3]:342",
"endCursor": "SmallUnsigned[4]:5550"
}
}
}
"#,
)
}

#[tokio::test]
async fn test_cursor_pagination_prev() {
let schema = get_schema().await;

assert_eq(
schema
.execute(
r#"
{
paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 3, cursor: "SmallUnsigned[4]:5550"}) {
edges {
node {
paymentId
amount
customer {
firstName
}
}
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
}
}
"#,
)
.await,
r#"
{
"paymentCursor": {
"edges": [
{
"node": {
"paymentId": 6409,
"amount": "11.99",
"customer": {
"firstName": "TANYA"
}
}
},
{
"node": {
"paymentId": 8272,
"amount": "11.99",
"customer": {
"firstName": "RICHARD"
}
}
},
{
"node": {
"paymentId": 9803,
"amount": "11.99",
"customer": {
"firstName": "NICHOLAS"
}
}
}
],
"pageInfo": {
"hasPreviousPage": true,
"hasNextPage": true,
"startCursor": "SmallUnsigned[4]:6409",
"endCursor": "SmallUnsigned[4]:9803"
}
}
}
"#,
)
}

#[tokio::test]
async fn test_cursor_pagination_no_next() {
let schema = get_schema().await;

assert_eq(
schema
.execute(
r#"
{
paymentCursor(filters: {amount: {gt: "11"}}, cursor: {limit: 3, cursor: "SmallUnsigned[4]:9803"}) {
edges {
node {
paymentId
amount
customer {
firstName
}
}
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
}
}
"#,
)
.await,
r#"
{
"paymentCursor": {
"edges": [
{
"node": {
"paymentId": 15821,
"amount": "11.99",
"customer": {
"firstName": "KENT"
}
}
},
{
"node": {
"paymentId": 15850,
"amount": "11.99",
"customer": {
"firstName": "TERRANCE"
}
}
}
],
"pageInfo": {
"hasPreviousPage": true,
"hasNextPage": false,
"startCursor": "SmallUnsigned[5]:15821",
"endCursor": "SmallUnsigned[5]:15850"
}
}
}
"#,
)
}
3 changes: 3 additions & 0 deletions examples/postgres/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_URL="postgres://postgres:[email protected]/sakila?currentSchema=public"
# COMPLEXITY_LIMIT=
# DEPTH_LIMIT=
64 changes: 17 additions & 47 deletions examples/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,23 @@
edition = '2021'
name = 'seaography-postgres-example'
version = '0.1.0'
[dependencies.async-graphql]
version = '4.0.10'
features = [
'decimal',
'chrono',
'dataloader',
]

[dependencies.async-graphql-poem]
version = '4.0.10'

[dependencies.async-trait]
version = '0.1.53'

[dependencies.heck]
version = '0.4.0'

[dependencies.itertools]
version = '0.10.3'

[dependencies.poem]
version = '1.3.29'

[dependencies.sea-orm]
version = '0.7.0'
features = [
'sqlx-postgres',
'runtime-async-std-native-tls',
]

[dependencies.seaography_derive]
path = '../../derive'

[dependencies.tokio]
version = '1.17.0'
features = [
'macros',
'rt-multi-thread',
]

[dependencies.tracing]
version = '0.1.34'

[dependencies.tracing-subscriber]
version = '0.3.11'
[dev-dependencies.serde_json]
version = '1.0.82'
[dependencies]
async-graphql = { version = "4.0.14", features = ["decimal", "chrono", "dataloader"] }
async-graphql-poem = { version = "4.0.14" }
async-trait = { version = "0.1.53" }
dotenv = "0.15.0"
heck = { version = "0.4.0" }
itertools = { version = "0.10.3" }
poem = { version = "1.3.29" }
sea-orm = { version = "^0.9", features = ["sqlx-postgres", "runtime-async-std-native-tls"] }
seaography = { version = "^0.1", path = "../../", features = [ "with-decimal", "with-chrono" ] } # TODO before production place version here
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.34" }
tracing-subscriber = { version = "0.3.11" }

[dev-dependencies]
serde_json = { version = '1.0.82' }

[workspace]
members = []
members = []
35 changes: 34 additions & 1 deletion examples/postgres/src/entities/actor.rs
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
# ! [doc = " SeaORM Entity. Generated by sea-orm-codegen 0.9.1"] use sea_orm :: entity :: prelude :: * ; # [derive (Copy , Clone , Default , Debug , DeriveEntity)] pub struct Entity ; impl EntityName for Entity { fn table_name (& self) -> & str { "actor" } } # [derive (Clone , Debug , PartialEq , DeriveModel , DeriveActiveModel , async_graphql :: SimpleObject , seaography_derive :: Filter)] # [sea_orm (table_name = "actor")] # [graphql (complex)] # [graphql (name = "Actor")] pub struct Model { pub actor_id : i32 , pub first_name : String , pub last_name : String , pub last_update : DateTime , } # [derive (Copy , Clone , Debug , EnumIter , DeriveColumn)] pub enum Column { ActorId , FirstName , LastName , LastUpdate , } # [derive (Copy , Clone , Debug , EnumIter , DerivePrimaryKey)] pub enum PrimaryKey { ActorId , } impl PrimaryKeyTrait for PrimaryKey { type ValueType = i32 ; fn auto_increment () -> bool { true } } # [derive (Copy , Clone , Debug , EnumIter)] pub enum Relation { FilmActor , } impl ColumnTrait for Column { type EntityName = Entity ; fn def (& self) -> ColumnDef { match self { Self :: ActorId => ColumnType :: Integer . def () , Self :: FirstName => ColumnType :: String (Some (45u32)) . def () , Self :: LastName => ColumnType :: String (Some (45u32)) . def () , Self :: LastUpdate => ColumnType :: DateTime . def () , } } } # [seaography_derive :: relation] impl RelationTrait for Relation { fn def (& self) -> RelationDef { match self { Self :: FilmActor => Entity :: has_many (super :: film_actor :: Entity) . into () , } } } impl Related < super :: film_actor :: Entity > for Entity { fn to () -> RelationDef { Relation :: FilmActor . def () } } impl ActiveModelBehavior for ActiveModel { }
use sea_orm::entity::prelude::*;

#[derive(
Clone,
Debug,
PartialEq,
DeriveEntityModel,
async_graphql::SimpleObject,
seaography::macros::Filter,
)]
#[sea_orm(table_name = "actor")]
#[graphql(complex)]
#[graphql(name = "Actor")]
pub struct Model {
#[sea_orm(primary_key)]
pub actor_id: i32,
pub first_name: String,
pub last_name: String,
pub last_update: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, seaography::macros::RelationsCompact)]
pub enum Relation {
#[sea_orm(has_many = "super::film_actor::Entity")]
FilmActor,
}

impl Related<super::film_actor::Entity> for Entity {
fn to() -> RelationDef {
Relation::FilmActor.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
Loading

0 comments on commit 8b7049b

Please sign in to comment.