Skip to content

Commit 1acda24

Browse files
authored
Merge pull request #30 from LiUGraphQL/filter-argument-should-not-be-added-for-non-lists
resolve issue #29
2 parents 81e6df8 + 5ff9284 commit 1acda24

File tree

3 files changed

+29
-41
lines changed

3 files changed

+29
-41
lines changed

graphql-api-generator/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def run(schema: GraphQLSchema, config: dict):
104104
if config.get('generation').get('query_list_of'):
105105
schema = add_list_of_types(schema)
106106
schema = add_list_queries(schema)
107-
schema = add_filters_to_type_fields(schema)
107+
#schema = add_filters_to_type_fields(schema)
108108

109109
# add input types
110110
if config.get('generation').get('input_to_create_objects'):

graphql-api-generator/resources/config.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ generation:
1111
# add reverse edges for traversal
1212
reverse_edges: true
1313
# add edge types
14-
#edge_types: false
15-
#fields_for_edge_types: false
14+
edge_types: false
15+
fields_for_edge_types: false
1616
# add queries
1717
query_by_id: true
1818
query_type_filter: true
19-
#query_list_of: true
19+
query_list_of: true
2020
# add input types
2121
input_to_create_objects: true
2222
input_to_update_objects: true
2323
# add edge input types (not supported)
24-
#input_to_create_edge_objects: false
25-
#input_to_update_edge_objects: false
24+
input_to_create_edge_objects: false
25+
input_to_update_edge_objects: false
2626
# add mutations
27-
#create_objects: true
28-
#update_objects: true
29-
#delete_objects: true
27+
create_objects: true
28+
update_objects: true
29+
delete_objects: true
3030
# add edge mutations (not supported)
31-
#create_edge_objects: false
32-
#update_edge_objects: false
33-
#delete_edge_objects: false
31+
create_edge_objects: false
32+
update_edge_objects: false
33+
delete_edge_objects: false

graphql-api-generator/utils/utils.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,23 @@ def add_type_filters(schema: GraphQLSchema):
412412

413413

414414
def add_object_type_filters(schema: GraphQLSchema):
415+
"""
416+
Add filters as arguments to list field of object types.
417+
:param schema:
418+
:return:
419+
"""
415420
for _type in schema.type_map.values():
416421
if not is_schema_defined_type(_type):
417422
continue
418423

419424
for field_name, field in _type.fields.items():
420-
inner_field_type = get_named_type(field.type)
421-
if is_enum_or_scalar(inner_field_type) or is_interface_type(inner_field_type):
425+
if not is_list_type(field.type):
422426
continue
423-
filter_name = f'_FilterFor{capitalize(inner_field_type.name)}'
427+
428+
named_type = get_named_type(field.type)
429+
if is_enum_or_scalar(named_type) or is_interface_type(named_type):
430+
continue
431+
filter_name = f'_FilterFor{capitalize(named_type.name)}'
424432
_filter = schema.type_map[filter_name]
425433
field.args['filter'] = GraphQLArgument(_filter)
426434
return schema
@@ -447,36 +455,16 @@ def add_enum_filters(schema: GraphQLSchema):
447455
continue
448456

449457
make += f'input _{enum_name}Filter {{' \
450-
f' _eq: {enum_name} ' \
451-
f' _neq: {enum_name} ' \
452-
f' _in: [{enum_name}] ' \
453-
f' _nin: [{enum_name}] ' \
454-
f'}} '
458+
f' _eq: {enum_name} ' \
459+
f' _neq: {enum_name} ' \
460+
f' _in: [{enum_name}] ' \
461+
f' _nin: [{enum_name}] ' \
462+
f'}} '
455463
schema = add_to_schema(schema, make)
456464
return schema
457465

458466

459-
def add_filters_to_type_fields(_schema: GraphQLSchema):
460-
"""
461-
Add filters as arguments to fields for object types.
462-
:param _schema:
463-
:return:
464-
"""
465-
for t in _schema.type_map.values():
466-
if not is_schema_defined_type(t):
467-
continue
468-
469-
# loop fields
470-
for n, f in t.fields.items():
471-
field_type = get_named_type(f.type)
472-
if not is_schema_defined_type(field_type) or is_interface_type(field_type):
473-
continue
474-
_filter = _schema.type_map[f'_FilterFor{field_type.name}']
475-
f.args['filter'] = GraphQLArgument(_filter)
476-
return _schema
477-
478-
479-
def add_create_mutations(schema):
467+
def add_create_mutations(schema: GraphQLSchema):
480468
"""
481469
Add mutations for creating object types.
482470
:param schema:

0 commit comments

Comments
 (0)