@@ -49,6 +49,10 @@ def cmd(args):
49
49
50
50
51
51
def run (schema : GraphQLSchema , config : dict ):
52
+ # check if DateTime exists, or should be added
53
+ if config .get ('generation' ).get ('generate_datetime' ) or config .get ('generation' ).get ('field_for_creation_date' ) or config .get ('generation' ).get ('field_for_last_update_date' ):
54
+ datetime_control (schema )
55
+
52
56
# validate
53
57
if config .get ('validate' ):
54
58
validate_names (schema , config .get ('validate' ))
@@ -68,13 +72,21 @@ def run(schema: GraphQLSchema, config: dict):
68
72
if config .get ('generation' ).get ('field_for_id' ):
69
73
schema = add_id_to_types (schema )
70
74
75
+ # add creationDate
76
+ if config .get ('generation' ).get ('field_for_creation_date' ):
77
+ schema = add_creation_date_to_types (schema )
78
+
79
+ # add lastUpdateDate
80
+ if config .get ('generation' ).get ('field_for_last_update_date' ):
81
+ schema = add_last_update_date_to_types (schema )
82
+
71
83
# add reverse edges for traversal
72
84
if config .get ('generation' ).get ('reverse_edges' ):
73
85
schema = add_reverse_edges (schema )
74
86
75
87
# add edge types
76
88
if config .get ('generation' ).get ('edge_types' ) or config .get ('generation' ).get ('create_edge_objects' ):
77
- schema = add_edge_objects (schema )
89
+ schema = add_edge_objects (schema , config . get ( 'generation' ). get ( 'field_for_creation_date' ), config . get ( 'generation' ). get ( 'field_for_last_update_date' ) )
78
90
if config .get ('generation' ).get ('fields_for_edge_types' ):
79
91
raise UnsupportedOperation ('{0} is currently not supported' .format ('fields_for_edge_types' ))
80
92
@@ -132,6 +144,7 @@ def run(schema: GraphQLSchema, config: dict):
132
144
133
145
134
146
def validate_names (schema : GraphQLSchema , validate ):
147
+
135
148
# types and interfaces
136
149
if validate .get ('type_names' ):
137
150
# type names
@@ -173,6 +186,7 @@ def validate_names(schema: GraphQLSchema, validate):
173
186
174
187
175
188
def transform_names (schema : GraphQLSchema , transform ):
189
+
176
190
# types and interfaces
177
191
if transform .get ('type_names' ):
178
192
if transform .get ('type_names' ) in string_transforms :
@@ -248,6 +262,17 @@ def drop_comments(schema):
248
262
field .description = None
249
263
250
264
265
+ def datetime_control (schema ):
266
+ type_names = set (schema .type_map .keys ())
267
+ if 'DateTime' in type_names :
268
+ if not is_scalar_type (schema .type_map ['DateTime' ]):
269
+ raise Exception ('DateTime exists but is not scalar type: ' + schema .type_map ['DateTime' ])
270
+ else :
271
+ schema .type_map ['DateTime' ] = GraphQLScalarType ('DateTime' )
272
+ if not is_scalar_type (schema .type_map ['DateTime' ]):
273
+ raise Exception ('DateTime could not be added as scalar!' )
274
+
275
+
251
276
if __name__ == '__main__' :
252
277
parser = argparse .ArgumentParser ()
253
278
parser .add_argument ('--input' , type = str , required = True ,
0 commit comments