Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace derive API with functional API #114

Merged
merged 64 commits into from
Mar 31, 2023
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
da7a67a
WIP prototype
karatakis Dec 6, 2022
357e925
Add filter and orderBy object generation
karatakis Dec 6, 2022
1dbf8ac
WIP filtering
karatakis Dec 13, 2022
5c3e35e
Fix filtering and add OrderBy
karatakis Dec 15, 2022
2b0bb7b
Register all entities
karatakis Dec 15, 2022
8330d03
Add pagination objects
karatakis Dec 15, 2022
ac0ef13
WIP functional pagination
karatakis Dec 18, 2022
484098f
WIP Pagination
karatakis Dec 18, 2022
cfe5606
Implement pagination
karatakis Dec 20, 2022
db055e1
Scaffold relations
karatakis Dec 21, 2022
272d5ab
Move functional API to seaography
karatakis Dec 29, 2022
23e4069
Enable related queries
karatakis Dec 29, 2022
a1cedc1
Fix generator for sqlite example
karatakis Dec 29, 2022
da215f6
Add support for selfRel and reverse
karatakis Dec 30, 2022
da383cb
Fix sqlite tests
karatakis Dec 30, 2022
06f987c
Update versions
karatakis Jan 10, 2023
dbd321b
Fix versions
karatakis Jan 10, 2023
ebad132
Fix generate of self relations
karatakis Jan 10, 2023
b27520b
Fix CLI and versions
karatakis Jan 10, 2023
a6f7088
Format code
karatakis Jan 10, 2023
8a4b3fa
Fix clippy recommendations
karatakis Jan 10, 2023
93c45f7
Work for making relations more flexible
karatakis Jan 10, 2023
55285ad
Update dependencies
karatakis Feb 18, 2023
3397b26
Add more types to connection
karatakis Feb 18, 2023
351595c
Update dependencies
karatakis Feb 18, 2023
8a64a0e
Add more types to filter
karatakis Feb 18, 2023
e4d5bad
Prepare for offset pagination
karatakis Feb 18, 2023
4cc9c25
Add offset_pagination
karatakis Feb 19, 2023
c861afa
WIP relations and reverse relations
karatakis Feb 19, 2023
24cdc85
Update versions & fix relations generating
karatakis Mar 1, 2023
8a92280
Delete legacy code
karatakis Mar 1, 2023
6a5ff79
Make CLI generator simpler
karatakis Mar 3, 2023
caea2a3
Update sqlite example
karatakis Mar 3, 2023
97e4e81
Fix workflows and format code
karatakis Mar 6, 2023
4bd8542
Fix workflows
karatakis Mar 6, 2023
d34e00f
Add basic support for enumeration
karatakis Mar 6, 2023
cb021de
Add enumeration filtering
karatakis Mar 7, 2023
8da4e0e
Fix Decimal type & postgres tests
karatakis Mar 7, 2023
5ac3404
Format Code
karatakis Mar 7, 2023
fcb795f
Fix clippy
karatakis Mar 7, 2023
480260d
Update mysql example
karatakis Mar 7, 2023
5da472a
Extend API to allow for customizations
karatakis Mar 17, 2023
89c7f5f
Fix enumerations
karatakis Mar 17, 2023
4251adc
Fix tests and enumerations
karatakis Mar 17, 2023
9b64077
Format Code
karatakis Mar 17, 2023
873d0cf
Fix clippy
karatakis Mar 17, 2023
c546ca4
Allow for custom field naming
karatakis Mar 22, 2023
492c5b7
Improve fields renaming
karatakis Mar 22, 2023
6bfcce8
Add field/entity guards
karatakis Mar 23, 2023
c1c610d
Fix some types
karatakis Mar 25, 2023
ae27c4f
Remove derive API
karatakis Mar 25, 2023
aee41e4
Remove trace of discoverer and derive
karatakis Mar 25, 2023
dc837d4
Update Readme.md
karatakis Mar 25, 2023
0e78ad1
Update Readme, Changelog, add enum tests
karatakis Mar 25, 2023
f8f3721
Add comments
karatakis Mar 30, 2023
773c5cc
Update lib.rs readme
karatakis Mar 30, 2023
b9724d0
Add guard tests
karatakis Mar 30, 2023
4be882f
Merge branch 'main' into functional-work
karatakis Mar 30, 2023
6a49d35
Fix linter errors
karatakis Mar 30, 2023
2357b14
Fix fmt errors
karatakis Mar 30, 2023
c4fa816
Fix tests
karatakis Mar 30, 2023
7e1071b
Update workflows with faster actions
karatakis Mar 30, 2023
882bf93
Add support for is_not_null
karatakis Mar 30, 2023
ff362cd
Fix formatting
karatakis Mar 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix filtering and add OrderBy
karatakis committed Dec 15, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5c3e35e2af2204486f992a54fcb13e476a37f306
59 changes: 41 additions & 18 deletions examples/sqlite/src/query_root.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_graphql::{dataloader::DataLoader, dynamic::*, Value};
use sea_orm::{prelude::*, Condition, Iterable};
use sea_orm::{prelude::*, Condition, Iterable, QueryOrder};
use seaography::heck::ToUpperCamelCase;

use crate::OrmDataloader;
@@ -12,6 +12,9 @@ pub fn schema(
) -> Result<Schema, SchemaError> {
let actor = entity_to_dynamic_graphql::<crate::entities::actor::Entity>();
let address = entity_to_dynamic_graphql::<crate::entities::address::Entity>();
let order_by_enum = Enum::new("OrderByEnum")
.item(EnumItem::new("Asc"))
.item(EnumItem::new("Desc"));

let query = Object::new("Query").field(actor.query).field(address.query);

@@ -22,6 +25,7 @@ pub fn schema(
.register(address.object)
.register(address.filter_input)
.register(address.order_input)
.register(order_by_enum)
.register(query);

let schema = if let Some(depth) = depth {
@@ -461,7 +465,7 @@ where
T::Column::iter().fold(InputObject::new(&name), |object, column| {
object.field(InputValue::new(
column.as_str(),
TypeRef::named(TypeRef::BOOLEAN),
TypeRef::named("OrderByEnum"),
))
})
}
@@ -481,23 +485,14 @@ where
move |ctx| {
FieldFuture::new(async move {
let filters = ctx.args.get("filters");

// if let Ok(v) = filters {
// v.object()?
// .iter()
// .for_each(|(name, val)| {
// println!("{:?}", name);
// println!("{:?}", val.object().unwrap().try_get("eq").unwrap().i64());
// });
// } else {
// println!("KEY filters is MISSING!")
// };
let order_by = ctx.args.get("orderBy");

let stmt = T::find();
let stmt = apply_filters(stmt, filters);
let stmt = apply_order(stmt, order_by);

let database = ctx.data::<DatabaseConnection>()?;
let data = T::find().all(database).await?;
let data = stmt.all(database).await?;
Ok(Some(FieldValue::list(
data.into_iter().map(|model| FieldValue::owned_any(model)),
)))
@@ -577,7 +572,7 @@ macro_rules! string_filtering_type {
pub fn apply_filters<T>(
stmt: Select<T>,
filters: Option<ValueAccessor>,
) -> Result<Select<T>, async_graphql::Error>
) -> Select<T>
where
T: EntityTrait,
<T as EntityTrait>::Model: Sync,
@@ -591,9 +586,9 @@ where

println!("Condition: {:?}", condition);

Ok(stmt.filter(condition))
stmt.filter(condition)
} else {
Ok(stmt)
stmt
}
}

@@ -707,4 +702,32 @@ where
};

condition
}
}

pub fn apply_order<T>(stmt: Select<T>, order_by: Option<ValueAccessor>) -> Select<T>
where
T: EntityTrait,
<T as EntityTrait>::Model: Sync,
{
if let Some(order_by) = order_by {
let order_by = order_by.object().expect("We expect the entity order_by to be object type");

T::Column::iter().fold(stmt, |stmt, column: T::Column| {
let order = order_by.get(column.as_str());

if let Some(order) = order {
let order = order.enum_name().expect("We expect the order of a column to be OrderByEnum");

match order {
"Asc" => stmt.order_by(column, sea_orm::Order::Asc),
"Desc" => stmt.order_by(column, sea_orm::Order::Desc),
_ => panic!("Order is not a valid OrderByEnum item")
}
} else {
stmt
}
})
} else {
stmt
}
}