Skip to content

Commit 992c2a4

Browse files
committed
merge with filter on returned types
2 parents b14af4b + e18b9f4 commit 992c2a4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

graphql-api-generator/generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def run(schema: GraphQLSchema, config: dict):
9999
if config.get('generation').get('query_list_of'):
100100
schema = add_list_of_types(schema)
101101
schema = add_list_queries(schema)
102+
schema = add_filters_to_type_fields(schema)
102103

103104
# add input types
104105
if config.get('generation').get('input_to_create_objects'):

graphql-api-generator/utils/utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,19 @@ def add_type_filters(schema: GraphQLSchema):
403403
if is_list_type(field.type):
404404
continue
405405

406+
<<<<<<< HEAD
406407
named_type = get_named_type(f_type)
407408
if is_enum_or_scalar(f_type):
408409
make += f'{field_name}: _{named_type.name}Filter '
409410
make += '} '
410411
schema = add_to_schema(schema, make)
411412
return schema
413+
=======
414+
# TODO check this!
415+
if is_list_type(f_type):
416+
# Unknown how filters would apply for lists, skip.
417+
continue
418+
>>>>>>> e18b9f42c901bf9f4c1ef03764c4ccfab1f83b7d
412419

413420

414421
def add_object_type_filters(schema):
@@ -447,7 +454,31 @@ def add_enum_filters(schema: GraphQLSchema):
447454
return schema
448455

449456

457+
<<<<<<< HEAD
450458
def add_create_mutations(schema: GraphQLSchema):
459+
=======
460+
def add_filters_to_type_fields(_schema: GraphQLSchema):
461+
"""
462+
Add filters as arguments to fields for object types.
463+
:param _schema:
464+
:return:
465+
"""
466+
for t in _schema.type_map.values():
467+
if not is_schema_defined_object_type(t) or t.name.startswith('_'):
468+
continue
469+
470+
# loop fields
471+
for n, f in t.fields.items():
472+
field_type = get_named_type(f.type)
473+
if not is_schema_defined_object_type(field_type) and not is_interface_type(field_type):
474+
continue
475+
_filter = _schema.type_map[f'_FilterFor{field_type.name}']
476+
f.args['filter'] = GraphQLArgument(_filter)
477+
return _schema
478+
479+
480+
def add_create_mutations(_schema):
481+
>>>>>>> e18b9f42c901bf9f4c1ef03764c4ccfab1f83b7d
451482
"""
452483
Add mutations for creating object types.
453484
:param schema:

0 commit comments

Comments
 (0)