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
  • Loading branch information
billy1624 committed Oct 7, 2024
1 parent df055bd commit 9a94954
Showing 1 changed file with 10 additions and 2 deletions.
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 9a94954

Please sign in to comment.