Skip to content

Commit

Permalink
Insert object allow nullable primary key and column with default value (
Browse files Browse the repository at this point in the history
#177)

* Insert object allow nullable primary key and column with default value

* Bump sea-orm
  • Loading branch information
billy1624 authored Oct 8, 2024
1 parent 5ae1f78 commit 3d20e36
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ categories = ["database"]

[dependencies]
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
sea-orm = { version = "~1.1.0-rc.1", default-features = false, features = ["seaography"] }
sea-orm = { version = "~1.1.0-rc.3", default-features = false, features = ["seaography"] }
itertools = { version = "0.12.0" }
heck = { version = "0.4.1" }
thiserror = { version = "1.0.44" }
Expand Down
2 changes: 1 addition & 1 deletion examples/mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ axum = { version = "0.7" }
async-graphql-axum = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "~1.1.0-rc.1", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] }
sea-orm = { version = "~1.1.0-rc.3", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ poem = { version = "3.0" }
async-graphql-poem = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "~1.1.0-rc.1", features = ["sqlx-postgres", "runtime-async-std-native-tls", "seaography"] }
sea-orm = { version = "~1.1.0-rc.3", features = ["sqlx-postgres", "runtime-async-std-native-tls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
Expand Down
2 changes: 1 addition & 1 deletion examples/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ actix-web = { version = "4.5", default-features = false, features = ["macros"] }
async-graphql-actix-web = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "~1.1.0-rc.1", features = ["sqlx-sqlite", "runtime-async-std-rustls", "seaography"] }
sea-orm = { version = "~1.1.0-rc.3", features = ["sqlx-sqlite", "runtime-async-std-rustls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
Expand Down
2 changes: 1 addition & 1 deletion generator/src/templates/actix_cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ actix-web = { version = "4.5", default-features = false, features = ["macros"] }
async-graphql-actix-web = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "~1.1.0-rc.1", features = ["<seaography-sql-library>", "runtime-async-std-native-tls", "seaography"] }
sea-orm = { version = "~1.1.0-rc.3", features = ["<seaography-sql-library>", "runtime-async-std-native-tls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
Expand Down
2 changes: 1 addition & 1 deletion generator/src/templates/axum_cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ axum = { version = "0.7" }
async-graphql-axum = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "~1.1.0-rc.1", features = ["<seaography-sql-library>", "runtime-async-std-native-tls", "seaography"] }
sea-orm = { version = "~1.1.0-rc.3", features = ["<seaography-sql-library>", "runtime-async-std-native-tls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
Expand Down
2 changes: 1 addition & 1 deletion generator/src/templates/poem_cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ poem = { version = "3.0" }
async-graphql-poem = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "~1.1.0-rc.1", features = ["<seaography-sql-library>", "runtime-async-std-native-tls", "seaography"] }
sea-orm = { version = "~1.1.0-rc.3", features = ["<seaography-sql-library>", "runtime-async-std-native-tls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
Expand Down
12 changes: 10 additions & 2 deletions src/inputs/entity_input.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use async_graphql::dynamic::{InputObject, InputValue, ObjectAccessor};
use sea_orm::{ColumnTrait, EntityTrait, Iterable};
use sea_orm::{ColumnTrait, EntityTrait, Iterable, PrimaryKeyToColumn, PrimaryKeyTrait};

use crate::{BuilderContext, EntityObjectBuilder, SeaResult, TypesMapHelper};

Expand Down Expand Up @@ -96,9 +96,17 @@ impl EntityInputBuilder {

let column_def = column.def();

let auto_increment = match <T::PrimaryKey as PrimaryKeyToColumn>::from_column(column) {
Some(_) => T::PrimaryKey::auto_increment(),
None => false,
};
let has_default_expr = column_def.get_column_default().is_some();
let is_insert_not_nullable =
is_insert && !(column_def.is_null() || auto_increment || has_default_expr);

let graphql_type = match types_map_helper.sea_orm_column_type_to_graphql_type(
column_def.get_column_type(),
!column_def.is_null() && is_insert,
is_insert_not_nullable,
) {
Some(type_name) => type_name,
None => return object,
Expand Down

0 comments on commit 3d20e36

Please sign in to comment.