Skip to content

Commit 01492e1

Browse files
committed
onConflict input types
1 parent 4b046c8 commit 01492e1

File tree

1 file changed

+101
-5
lines changed

1 file changed

+101
-5
lines changed

src/graphql.rs

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ pub enum __Type {
515515
// Mutation
516516
Mutation(MutationType),
517517
InsertInput(InsertInputType),
518+
InsertOnConflictInput(InsertOnConflictType),
518519
InsertResponse(InsertResponseType),
519520
UpdateInput(UpdateInputType),
520521
UpdateResponse(UpdateResponseType),
@@ -593,6 +594,7 @@ impl ___Type for __Type {
593594
Self::Node(x) => x.kind(),
594595
Self::NodeInterface(x) => x.kind(),
595596
Self::InsertInput(x) => x.kind(),
597+
Self::InsertOnConflictInput(x) => x.kind(),
596598
Self::InsertResponse(x) => x.kind(),
597599
Self::UpdateInput(x) => x.kind(),
598600
Self::UpdateResponse(x) => x.kind(),
@@ -628,6 +630,7 @@ impl ___Type for __Type {
628630
Self::Node(x) => x.name(),
629631
Self::NodeInterface(x) => x.name(),
630632
Self::InsertInput(x) => x.name(),
633+
Self::InsertOnConflictInput(x) => x.name(),
631634
Self::InsertResponse(x) => x.name(),
632635
Self::UpdateInput(x) => x.name(),
633636
Self::UpdateResponse(x) => x.name(),
@@ -663,6 +666,7 @@ impl ___Type for __Type {
663666
Self::Node(x) => x.description(),
664667
Self::NodeInterface(x) => x.description(),
665668
Self::InsertInput(x) => x.description(),
669+
Self::InsertOnConflictInput(x) => x.description(),
666670
Self::InsertResponse(x) => x.description(),
667671
Self::UpdateInput(x) => x.description(),
668672
Self::UpdateResponse(x) => x.description(),
@@ -699,6 +703,7 @@ impl ___Type for __Type {
699703
Self::Node(x) => x.fields(_include_deprecated),
700704
Self::NodeInterface(x) => x.fields(_include_deprecated),
701705
Self::InsertInput(x) => x.fields(_include_deprecated),
706+
Self::InsertOnConflictInput(x) => x.fields(_include_deprecated),
702707
Self::InsertResponse(x) => x.fields(_include_deprecated),
703708
Self::UpdateInput(x) => x.fields(_include_deprecated),
704709
Self::UpdateResponse(x) => x.fields(_include_deprecated),
@@ -735,6 +740,7 @@ impl ___Type for __Type {
735740
Self::Node(x) => x.interfaces(),
736741
Self::NodeInterface(x) => x.interfaces(),
737742
Self::InsertInput(x) => x.interfaces(),
743+
Self::InsertOnConflictInput(x) => x.interfaces(),
738744
Self::InsertResponse(x) => x.interfaces(),
739745
Self::UpdateInput(x) => x.interfaces(),
740746
Self::UpdateResponse(x) => x.interfaces(),
@@ -780,6 +786,7 @@ impl ___Type for __Type {
780786
Self::Node(x) => x.enum_values(_include_deprecated),
781787
Self::NodeInterface(x) => x.enum_values(_include_deprecated),
782788
Self::InsertInput(x) => x.enum_values(_include_deprecated),
789+
Self::InsertOnConflictInput(x) => x.enum_values(),
783790
Self::InsertResponse(x) => x.enum_values(_include_deprecated),
784791
Self::UpdateInput(x) => x.enum_values(_include_deprecated),
785792
Self::UpdateResponse(x) => x.enum_values(_include_deprecated),
@@ -816,6 +823,7 @@ impl ___Type for __Type {
816823
Self::Node(x) => x.input_fields(),
817824
Self::NodeInterface(x) => x.input_fields(),
818825
Self::InsertInput(x) => x.input_fields(),
826+
Self::InsertOnConflictInput(x) => x.input_fields(),
819827
Self::InsertResponse(x) => x.input_fields(),
820828
Self::UpdateInput(x) => x.input_fields(),
821829
Self::UpdateResponse(x) => x.input_fields(),
@@ -962,6 +970,12 @@ pub struct InsertResponseType {
962970
pub schema: Arc<__Schema>,
963971
}
964972

973+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
974+
pub struct InsertOnConflictType {
975+
pub table: Arc<Table>,
976+
pub schema: Arc<__Schema>,
977+
}
978+
965979
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
966980
pub struct UpdateResponseType {
967981
pub table: Arc<Table>,
@@ -1445,14 +1459,16 @@ impl ___Type for MutationType {
14451459
sql_type: None,
14461460
},
14471461
__InputValue {
1448-
name_: "update".to_string(),
1462+
name_: "onConflict".to_string(),
14491463
type_: __Type::NonNull(NonNullType {
14501464
type_: Box::new(__Type::List(ListType {
14511465
type_: Box::new(__Type::NonNull(NonNullType {
1452-
type_: Box::new(__Type::InsertInput(InsertInputType {
1453-
table: Arc::clone(table),
1454-
schema: Arc::clone(&self.schema),
1455-
})),
1466+
type_: Box::new(__Type::InsertOnConflictInput(
1467+
InsertOnConflictType {
1468+
table: Arc::clone(table),
1469+
schema: Arc::clone(&self.schema),
1470+
},
1471+
)),
14561472
})),
14571473
})),
14581474
}),
@@ -1693,6 +1709,8 @@ impl ___Type for EnumType {
16931709
EnumSource::TableColumns(table) => table
16941710
.columns
16951711
.iter()
1712+
// TODO: is this the right thing to filter on?
1713+
.filter(|x| x.permissions.is_selectable)
16961714
.map(|col| __EnumValue {
16971715
name: self.schema.graphql_column_field_name(col),
16981716
description: None,
@@ -3132,6 +3150,80 @@ impl ___Type for InsertInputType {
31323150
}
31333151
}
31343152

3153+
impl ___Type for InsertOnConflictType {
3154+
fn kind(&self) -> __TypeKind {
3155+
__TypeKind::INPUT_OBJECT
3156+
}
3157+
3158+
fn name(&self) -> Option<String> {
3159+
Some(format!(
3160+
"{}OnConflictInput",
3161+
self.schema.graphql_table_base_type_name(&self.table)
3162+
))
3163+
}
3164+
3165+
fn fields(&self, _include_deprecated: bool) -> Option<Vec<__Field>> {
3166+
None
3167+
}
3168+
3169+
fn input_fields(&self) -> Option<Vec<__InputValue>> {
3170+
Some(vec![
3171+
__InputValue {
3172+
// TODO: Create a custom type for available constraints
3173+
name_: "constraint".to_string(),
3174+
// If triggers are involved, we can't detect if a field is non-null. Default
3175+
// all fields to non-null and let postgres errors handle it.
3176+
type_: __Type::NonNull(NonNullType {
3177+
type_: Box::new(__Type::List(ListType {
3178+
type_: Box::new(__Type::NonNull(NonNullType {
3179+
type_: Box::new(__Type::Enum(EnumType {
3180+
enum_: EnumSource::TableColumns(Arc::clone(&self.table)),
3181+
schema: Arc::clone(&self.schema),
3182+
})),
3183+
})),
3184+
})),
3185+
}),
3186+
description: Some(
3187+
"A unique constraint that may conflict with the inserted records".to_string(),
3188+
),
3189+
default_value: None,
3190+
sql_type: None,
3191+
},
3192+
__InputValue {
3193+
name_: "updateFields".to_string(),
3194+
// If triggers are involved, we can't detect if a field is non-null. Default
3195+
// all fields to non-null and let postgres errors handle it.
3196+
type_: __Type::NonNull(NonNullType {
3197+
type_: Box::new(__Type::List(ListType {
3198+
type_: Box::new(__Type::NonNull(NonNullType {
3199+
type_: Box::new(__Type::Enum(EnumType {
3200+
enum_: EnumSource::TableColumns(Arc::clone(&self.table)),
3201+
schema: Arc::clone(&self.schema),
3202+
})),
3203+
})),
3204+
})),
3205+
}),
3206+
description: Some("Fields to be updated if conflict occurs".to_string()),
3207+
default_value: None,
3208+
sql_type: None,
3209+
},
3210+
__InputValue {
3211+
name_: "filter".to_string(),
3212+
type_: __Type::FilterEntity(FilterEntityType {
3213+
table: Arc::clone(&self.table),
3214+
schema: self.schema.clone(),
3215+
}),
3216+
description: Some(
3217+
"Filters to apply to the results set when querying from the collection"
3218+
.to_string(),
3219+
),
3220+
default_value: None,
3221+
sql_type: None,
3222+
},
3223+
])
3224+
}
3225+
}
3226+
31353227
impl ___Type for InsertResponseType {
31363228
fn kind(&self) -> __TypeKind {
31373229
__TypeKind::OBJECT
@@ -4197,6 +4289,10 @@ impl __Schema {
41974289
enum_: EnumSource::TableColumns(Arc::clone(table)),
41984290
schema: Arc::clone(&schema_rc),
41994291
}));
4292+
types_.push(__Type::InsertOnConflictType(InsertOnConflictType {
4293+
table: Arc::clone(table),
4294+
schema: Arc::clone(&schema_rc),
4295+
}));
42004296
}
42014297

42024298
if self.graphql_table_update_types_are_valid(table) {

0 commit comments

Comments
 (0)