@@ -516,12 +516,64 @@ def add_object_type_filters(schema: GraphQLSchema):
516
516
return schema
517
517
518
518
519
+ def add_create_edge_objects (schema : GraphQLSchema ):
520
+ make = ''
521
+ for _type in schema .type_map .values ():
522
+ if not is_schema_defined_type (_type ) or is_interface_type (_type ):
523
+ continue
524
+
525
+ for field_name , field in _type .fields .items ():
526
+ if field_name [0 ] == '_' :
527
+ continue
528
+ field_type = field .type
529
+ inner_field_type = get_named_type (field_type )
530
+ if is_scalar_type (inner_field_type ) or is_enum_type (inner_field_type ):
531
+ continue
532
+
533
+ if is_interface_type (_type ):
534
+ connected_types = schema .get_possible_types (_type )
535
+ else :
536
+ connected_types = [_type ]
537
+
538
+ for t in connected_types :
539
+ edge_from = f'{ capitalize (field_name )} EdgeFrom{ t .name } '
540
+ edge_create = f'create{ edge_from } '
541
+ edge_input = f'_InputToCreate{ edge_from } '
542
+ annotate_input = f'_InputToAnnotate{ edge_from } '
543
+
544
+ annotation_fields = []
545
+ for arg , arg_type in field .args .items ():
546
+ if arg == 'filter' :
547
+ continue
548
+ # if not is_scalar_type(arg_type.type.name) and not is_enum_type(arg_type.type.name):
549
+ # raise Exception("Fields cannot be object types")
550
+ annotation_fields .append (f'{ arg } : { arg_type .type } ' )
551
+ annotations = " " .join (annotation_fields )
552
+
553
+ if len (annotations ) > 0 :
554
+ make += f'input { edge_input } {{sourceID: ID! targetID: ID! annotations: { annotate_input } }}\n '
555
+ make += f'input { annotate_input } {{{ annotations } }}\n '
556
+ make += f'type _{ edge_from } {{id:ID! source: { t .name } ! target: { inner_field_type } ! { annotations } }}\n '
557
+ else :
558
+ make += f'input { edge_input } {{sourceID: ID! targetID: ID!}}\n '
559
+ make += f'type _{ edge_from } {{id: ID! source: { t .name } ! target: { inner_field_type } !}}\n '
560
+ make += f'extend type Mutation{{{ edge_create } (data: { edge_input } ):_{ edge_from } }}\n '
561
+
562
+ schema = add_to_schema (schema , make )
563
+ return schema
564
+
565
+
519
566
def remove_field_arguments_for_types (schema : GraphQLSchema ):
567
+ keep_args = ['filter' ]
520
568
for _type in schema .type_map .values ():
521
569
if not is_schema_defined_type (_type ):
522
570
continue
523
571
for field_name , field in _type .fields .items ():
524
- field .args = {}
572
+ args = {}
573
+ for arg in field .args :
574
+ if arg in keep_args :
575
+ args [arg ] = field .args [arg ]
576
+ field .args = args
525
577
return schema
526
578
527
579
0 commit comments