@@ -36,14 +36,27 @@ def decapitalize(string: str):
36
36
return string [0 ].lower () + string [1 :]
37
37
38
38
39
- def is_schema_defined_type (_type : GraphQLType ):
39
+ def is_db_schema_defined_type (_type : GraphQLType ):
40
40
"""
41
- Returns true if a type is a schema-defined GraphQL type.
41
+ Returns true if _type is a GraphQL type defined in the DB schema .
42
42
:param _type:
43
43
:return:
44
44
"""
45
45
if is_input_type (_type ) or _type .name .startswith ('_' ) or _type .name == 'Mutation' or _type .name == 'Query' :
46
46
return False
47
+
48
+ return True
49
+
50
+
51
+ def is_schema_defined_type (_type : GraphQLType ):
52
+ """
53
+ Returns true if _type is a schema-defined GraphQL type.
54
+ :param _type:
55
+ :return:
56
+ """
57
+ if is_input_type (_type ) or _type .name .startswith ('__' ) or _type .name == 'Mutation' or _type .name == 'Query' :
58
+ return False
59
+
47
60
return True
48
61
49
62
@@ -89,7 +102,7 @@ def add_id_to_types(schema: GraphQLSchema):
89
102
"""
90
103
make = ''
91
104
for _type in schema .type_map .values ():
92
- if not is_schema_defined_type (_type ):
105
+ if not is_db_schema_defined_type (_type ):
93
106
continue
94
107
if is_interface_type (_type ):
95
108
make += f'extend interface { _type .name } {{ id: ID! }} '
@@ -108,6 +121,7 @@ def add_creation_date_to_types(schema: GraphQLSchema):
108
121
for _type in schema .type_map .values ():
109
122
if not is_schema_defined_type (_type ):
110
123
continue
124
+
111
125
if is_interface_type (_type ):
112
126
make += f'extend interface { _type .name } {{ _creationDate: DateTime! }} '
113
127
else :
@@ -168,7 +182,7 @@ def add_reverse_edges(schema: GraphQLSchema):
168
182
"""
169
183
make = ''
170
184
for _type in schema .type_map .values ():
171
- if not is_schema_defined_type (_type ):
185
+ if not is_db_schema_defined_type (_type ):
172
186
continue
173
187
174
188
for field_name , field_type in _type .fields .items ():
@@ -200,15 +214,15 @@ def add_input_to_create(schema: GraphQLSchema):
200
214
# add create types (placeholders)
201
215
make = ''
202
216
for _type in schema .type_map .values ():
203
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
217
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
204
218
continue
205
219
make += f'input _InputToCreate{ _type .name } '
206
220
schema = add_to_schema (schema , make )
207
221
208
222
# add fields to create types
209
223
make = ''
210
224
for _type in schema .type_map .values ():
211
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
225
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
212
226
continue
213
227
make += f'\n extend input _InputToCreate{ _type .name } {{ '
214
228
for field_name , field in _type .fields .items ():
@@ -248,7 +262,7 @@ def add_key_input_types(schema: GraphQLSchema):
248
262
make_types = ''
249
263
extend_fields = ''
250
264
for _type in schema .type_map .values ():
251
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
265
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
252
266
continue
253
267
keys = _get_keys_for_type (_type )
254
268
# TODO: Modify this when we need to handle multiple keys.
@@ -279,7 +293,7 @@ def add_key_queries(schema: GraphQLSchema):
279
293
# Create queries for object types
280
294
make = ''
281
295
for _type in schema .type_map .values ():
282
- if not is_schema_defined_type (_type ):
296
+ if not is_db_schema_defined_type (_type ):
283
297
continue
284
298
keys = _get_keys_for_type (_type )
285
299
# TODO: Handle multiple keys here, somehow.
@@ -329,7 +343,7 @@ def add_input_update(schema: GraphQLSchema):
329
343
# Create update inputs
330
344
make = ''
331
345
for _type in schema .type_map .values ():
332
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
346
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
333
347
continue
334
348
update_name = f'_InputToUpdate{ _type .name } '
335
349
make += f'input { update_name } '
@@ -338,7 +352,7 @@ def add_input_update(schema: GraphQLSchema):
338
352
# Add fields to update type
339
353
make = ''
340
354
for _type in schema .type_map .values ():
341
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
355
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
342
356
continue
343
357
for field_name , field in _type .fields .items ():
344
358
if field_name == 'id' or field_name [0 ] == '_' :
@@ -368,7 +382,7 @@ def add_get_queries(schema: GraphQLSchema):
368
382
# Create queries for object types
369
383
make = ''
370
384
for _type in schema .type_map .values ():
371
- if not is_schema_defined_type (_type ):
385
+ if not is_db_schema_defined_type (_type ):
372
386
continue
373
387
make += f'extend type Query {{ { decapitalize (_type .name )} (id:ID!): { _type .name } }} '
374
388
schema = add_to_schema (schema , make )
@@ -383,7 +397,7 @@ def add_list_of_types(schema: GraphQLSchema):
383
397
"""
384
398
make = ''
385
399
for _type in schema .type_map .values ():
386
- if not is_schema_defined_type (_type ):
400
+ if not is_db_schema_defined_type (_type ):
387
401
continue
388
402
389
403
make += f'type _ListOf{ _type .name } s {{ ' \
@@ -403,7 +417,7 @@ def add_list_queries(schema: GraphQLSchema):
403
417
"""
404
418
make = ''
405
419
for _type in schema .type_map .values ():
406
- if not is_schema_defined_type (_type ):
420
+ if not is_db_schema_defined_type (_type ):
407
421
continue
408
422
make += f'extend type Query {{ ' \
409
423
f' listOf{ _type .name } s(first:Int=10, after:ID="", filter:_FilterFor{ _type .name } ): _ListOf{ _type .name } s ' \
@@ -523,7 +537,7 @@ def add_type_filters(schema: GraphQLSchema, field_for_creation_date, field_for_l
523
537
"""
524
538
make = ''
525
539
for _type in schema .type_map .values ():
526
- if not is_schema_defined_type (_type ):
540
+ if not is_db_schema_defined_type (_type ):
527
541
continue
528
542
529
543
make += f'input _FilterFor{ _type .name } {{ ' \
@@ -560,7 +574,7 @@ def add_object_type_filters(schema: GraphQLSchema):
560
574
:return:
561
575
"""
562
576
for _type in schema .type_map .values ():
563
- if not is_schema_defined_type (_type ):
577
+ if not is_db_schema_defined_type (_type ):
564
578
continue
565
579
566
580
for field_name , field in _type .fields .items ():
@@ -588,16 +602,10 @@ def get_field_annotations(field: GraphQLField):
588
602
return " " .join (annotation_fields )
589
603
590
604
591
- def add_edge_objects (schema : GraphQLSchema , field_for_creation_date , field_for_last_update_date ):
605
+ def add_edge_objects (schema : GraphQLSchema ):
592
606
make = ''
593
- creation_date_string = ''
594
- last_update_date_string = ''
595
- if field_for_creation_date :
596
- creation_date_string = '_creationDate: DateTime!'
597
- if field_for_last_update_date :
598
- last_update_date_string = '_lastUpdateDate: DateTime'
599
607
for _type in schema .type_map .values ():
600
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
608
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
601
609
continue
602
610
connected_types = schema .get_possible_types (_type ) if is_interface_type (_type ) else [_type ]
603
611
for field_name , field in _type .fields .items ():
@@ -607,7 +615,7 @@ def add_edge_objects(schema: GraphQLSchema, field_for_creation_date, field_for_l
607
615
for t in connected_types :
608
616
edge_from = f'{ capitalize (field_name )} EdgeFrom{ t .name } '
609
617
annotations = get_field_annotations (field )
610
- make += f'type _{ edge_from } {{id:ID! source: { t .name } ! target: { inner_field_type } ! { creation_date_string } { last_update_date_string } { annotations } }}\n '
618
+ make += f'type _{ edge_from } {{id:ID! source: { t .name } ! target: { inner_field_type } ! { annotations } }}\n '
611
619
612
620
schema = add_to_schema (schema , make )
613
621
return schema
@@ -616,7 +624,7 @@ def add_edge_objects(schema: GraphQLSchema, field_for_creation_date, field_for_l
616
624
def add_input_to_create_edge_objects (schema : GraphQLSchema ):
617
625
make = ''
618
626
for _type in schema .type_map .values ():
619
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
627
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
620
628
continue
621
629
connected_types = schema .get_possible_types (_type ) if is_interface_type (_type ) else [_type ]
622
630
for field_name , field in _type .fields .items ():
@@ -642,7 +650,7 @@ def add_input_to_create_edge_objects(schema: GraphQLSchema):
642
650
def add_mutation_create_edge_objects (schema : GraphQLSchema ):
643
651
make = ''
644
652
for _type in schema .type_map .values ():
645
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
653
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
646
654
continue
647
655
connected_types = schema .get_possible_types (_type ) if is_interface_type (_type ) else [_type ]
648
656
for field_name , field in _type .fields .items ():
@@ -662,7 +670,7 @@ def add_mutation_create_edge_objects(schema: GraphQLSchema):
662
670
def remove_field_arguments_for_types (schema : GraphQLSchema ):
663
671
keep_args = ['filter' ]
664
672
for _type in schema .type_map .values ():
665
- if not is_schema_defined_type (_type ):
673
+ if not is_db_schema_defined_type (_type ):
666
674
continue
667
675
for field_name , field in _type .fields .items ():
668
676
args = {}
@@ -702,7 +710,7 @@ def add_create_mutations(schema: GraphQLSchema):
702
710
"""
703
711
make = ''
704
712
for _type in schema .type_map .values ():
705
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
713
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
706
714
continue
707
715
create = f'create{ _type .name } '
708
716
input_type = f'_InputToCreate{ _type .name } '
@@ -720,7 +728,7 @@ def add_update_mutations(schema: GraphQLSchema):
720
728
"""
721
729
make = ''
722
730
for _type in schema .type_map .values ():
723
- if not is_schema_defined_type (_type ) or is_interface_type (_type ):
731
+ if not is_db_schema_defined_type (_type ) or is_interface_type (_type ):
724
732
continue
725
733
update = f'update{ capitalize (_type .name )} '
726
734
input_type = f'_InputToUpdate{ _type .name } '
@@ -738,7 +746,7 @@ def add_delete_mutations(schema: GraphQLSchema):
738
746
"""
739
747
make = ''
740
748
for _type in schema .type_map .values ():
741
- if not is_schema_defined_type (_type ):
749
+ if not is_db_schema_defined_type (_type ):
742
750
continue
743
751
delete = f'delete{ _type .name } '
744
752
make += f'extend type Mutation {{ { delete } (id: ID!): { _type .name } }} '
0 commit comments