File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,14 @@ def run(schema: GraphQLSchema, config: dict):
68
68
if config .get ('generation' ).get ('field_for_id' ):
69
69
schema = add_id_to_types (schema )
70
70
71
+ # add creationDate
72
+ if config .get ('generation' ).get ('field_for_creation_date' ):
73
+ schema = add_creation_date_to_types (schema )
74
+
75
+ # add lastUpdateDate
76
+ if config .get ('generation' ).get ('field_for_last_update_date' ):
77
+ schema = add_last_update_date_to_types (schema )
78
+
71
79
# add reverse edges for traversal
72
80
if config .get ('generation' ).get ('reverse_edges' ):
73
81
schema = add_reverse_edges (schema )
Original file line number Diff line number Diff line change @@ -98,6 +98,40 @@ def add_id_to_types(schema: GraphQLSchema):
98
98
return add_to_schema (schema , make )
99
99
100
100
101
+ def add_creation_date_to_types (schema : GraphQLSchema ):
102
+ """
103
+ Extend all object types in the schema with an creationDate field.
104
+ :param schema:
105
+ :return:
106
+ """
107
+ make = ''
108
+ for _type in schema .type_map .values ():
109
+ if not is_schema_defined_type (_type ):
110
+ continue
111
+ if is_interface_type (_type ):
112
+ make += f'extend interface { _type .name } {{ _creationDate: Date! }} '
113
+ else :
114
+ make += f'extend type { _type .name } {{ _creationDate: Date! }} '
115
+ return add_to_schema (schema , make )
116
+
117
+
118
+ def add_last_update_date_to_types (schema : GraphQLSchema ):
119
+ """
120
+ Extend all object types in the schema with an lastUpdateDate field.
121
+ :param schema:
122
+ :return:
123
+ """
124
+ make = ''
125
+ for _type in schema .type_map .values ():
126
+ if not is_schema_defined_type (_type ):
127
+ continue
128
+ if is_interface_type (_type ):
129
+ make += f'extend interface { _type .name } {{ _lastUpdateDate: Date }} '
130
+ else :
131
+ make += f'extend type { _type .name } {{ _lastUpdateDate: Date }} '
132
+ return add_to_schema (schema , make )
133
+
134
+
101
135
def copy_wrapper_structure (_type : GraphQLType , original : GraphQLType ):
102
136
"""
103
137
Copy the wrapper structure of original to _type.
You can’t perform that action at this time.
0 commit comments