Skip to content

Commit dadd2cb

Browse files
committed
Add a dummy field _dummy to all types and input types which have no visible fields.
1 parent d21e68b commit dadd2cb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

graphql-api-generator/utils/utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ def add_input_to_create(schema: GraphQLSchema):
248248
if not is_db_schema_defined_type(_type) or is_interface_type(_type):
249249
continue
250250
make += f'\nextend input _InputToCreate{_type.name} {{\n'
251+
num_fields = 0
251252
for field_name, field in _type.fields.items():
252253
if field_name == 'id' or field_name[0] == '_':
253254
continue
254-
255+
num_fields += 1
255256
inner_field_type = get_named_type(field.type)
256257

257258
if is_enum_or_scalar(inner_field_type):
@@ -261,6 +262,8 @@ def add_input_to_create(schema: GraphQLSchema):
261262
connect_name = f'_InputToConnect{capitalize(field_name)}Of{_type.name}'
262263
connect = copy_wrapper_structure(schema.type_map[connect_name], field.type)
263264
make += f' {field_name}: {connect} \n'
265+
if num_fields == 0:
266+
make += f' _dummy: String \n'
264267
make += '}\n'
265268
schema = add_to_schema(schema, make)
266269
return schema
@@ -392,11 +395,12 @@ def add_input_update(schema: GraphQLSchema):
392395
for _type in schema.type_map.values():
393396
if not is_db_schema_defined_type(_type) or is_interface_type(_type):
394397
continue
398+
num_fields = 0
399+
update_name = f'_InputToUpdate{_type.name}'
395400
for field_name, field in _type.fields.items():
396401
if field_name == 'id' or field_name[0] == '_':
397402
continue
398-
399-
update_name = f'_InputToUpdate{_type.name}'
403+
num_fields += 1
400404
f_type = get_nullable_type(field.type)
401405
inner_field_type = get_named_type(f_type)
402406

@@ -407,6 +411,8 @@ def add_input_update(schema: GraphQLSchema):
407411
connect_name = f'_InputToConnect{capitalize(field_name)}Of{_type.name}'
408412
connect = copy_wrapper_structure(schema.get_type(connect_name), f_type)
409413
make += f'extend input {update_name} {{ {field_name}: {connect} }} \n'
414+
if num_fields == 0:
415+
make += f'extend input {update_name} {{ _dummy: String }} \n'
410416
schema = add_to_schema(schema, make)
411417
return schema
412418

@@ -886,6 +892,9 @@ def get_field_directives(field_name, _type, schema):
886892
:return string:
887893
"""
888894

895+
if field_name == '_dummy':
896+
return ''
897+
889898
output = ''
890899

891900
# Used to make sure we don't add the same directive multiple times to the same field

0 commit comments

Comments
 (0)