Skip to content

Commit 6d5e174

Browse files
committed
Fixed the bug with missing default field arguments
1 parent fa99fe9 commit 6d5e174

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**v0.1.0, released on ???**
22
* New feature: Edge annotations can now be set when creating and/or updating objects. See: https://github.com/LiUGraphQL/woo.sh/issues/24
3+
* Bug fix: Default values missing from field arguments is now fixed.
34
* ...

graphql-api-generator/utils/utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,25 @@ def get_type_directives(_type, schema):
961961
return output
962962

963963

964+
def get_argument_as_string(arg_name, arg):
965+
"""
966+
Returns the argument as string ready for output, including default values if existent
967+
:param arg_name:
968+
:param arg:
969+
:return string:
970+
"""
971+
972+
ret = f'{arg_name}: {arg.type}'
973+
974+
if arg.default_value != INVALID:
975+
if isinstance(arg.default_value, str):
976+
ret += f'="{arg.default_value}"'
977+
else:
978+
ret += f'={arg.default_value}'
979+
980+
return ret
981+
982+
964983
def print_schema_with_directives(schema):
965984
"""
966985
Outputs the given schema as string, in the format we want it.
@@ -1038,7 +1057,7 @@ def print_schema_with_directives(schema):
10381057

10391058
# Get arguments for field
10401059
if hasattr(field, 'args') and field.args:
1041-
args = ', '.join([f'{arg_name}: {arg.type}' for arg_name, arg in field.args.items()])
1060+
args = ', '.join([f'{get_argument_as_string(arg_name, arg)}' for arg_name, arg in field.args.items()])
10421061
output += f'({args})'
10431062

10441063
output += ': ' + str(field.type)

0 commit comments

Comments
 (0)