Skip to content

Commit 8fea088

Browse files
committed
Added support for creation and last update date to edges
1 parent a441e1d commit 8fea088

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

graphql-api-generator/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run(schema: GraphQLSchema, config: dict):
8282

8383
# add edge types
8484
if config.get('generation').get('edge_types') or config.get('generation').get('create_edge_objects'):
85-
schema = add_edge_objects(schema)
85+
schema = add_edge_objects(schema, config.get('generation').get('field_for_creation_date'), config.get('generation').get('field_for_last_update_date'))
8686
if config.get('generation').get('fields_for_edge_types'):
8787
raise UnsupportedOperation('{0} is currently not supported'.format('fields_for_edge_types'))
8888

graphql-api-generator/utils/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,14 @@ def get_field_annotations(field: GraphQLField):
560560
return " ".join(annotation_fields)
561561

562562

563-
def add_edge_objects(schema: GraphQLSchema):
563+
def add_edge_objects(schema: GraphQLSchema, field_for_creation_date, field_for_last_update_date):
564564
make = ''
565+
creation_date_string = ''
566+
last_update_date_string = ''
567+
if field_for_creation_date:
568+
creation_date_string = '_creationDate: Date!'
569+
if field_for_last_update_date:
570+
last_update_date_string = '_lastUpdateDate: Date'
565571
for _type in schema.type_map.values():
566572
if not is_schema_defined_type(_type) or is_interface_type(_type):
567573
continue
@@ -573,7 +579,7 @@ def add_edge_objects(schema: GraphQLSchema):
573579
for t in connected_types:
574580
edge_from = f'{capitalize(field_name)}EdgeFrom{t.name}'
575581
annotations = get_field_annotations(field)
576-
make += f'type _{edge_from} {{id:ID! source: {t.name}! target: {inner_field_type}! {annotations}}}\n'
582+
make += f'type _{edge_from} {{id:ID! source: {t.name}! target: {inner_field_type}! {creation_date_string} {last_update_date_string} {annotations}}}\n'
577583

578584
schema = add_to_schema(schema, make)
579585
return schema

0 commit comments

Comments
 (0)