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 8, 2022
1 parent 8c9cb34 commit 71086e9
Show file tree
Hide file tree
Showing 4 changed files with 637 additions and 3 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 @@ -197,3 +197,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=
Loading

0 comments on commit 71086e9

Please sign in to comment.