Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Argument type only uses scalar and ignore list #327

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions ariadne_codegen/client_generators/custom_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLInterfaceType,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLScalarType,
Expand Down Expand Up @@ -93,8 +94,7 @@ def generate_arguments(
return_arguments_values,
arg_name,
name,
final_type,
is_required,
arg_value.type,
used_custom_scalar,
)

Expand Down Expand Up @@ -125,12 +125,11 @@ def _accumulate_return_arguments(
return_arguments_values: List[ast.expr],
arg_name: str,
name: str,
final_type: Union[GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType],
is_required: bool,
complete_type: Union[GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType],
used_custom_scalar: Optional[str],
) -> None:
"""Accumulates return arguments."""
constant_value = f"{final_type.name}!" if is_required else final_type.name
constant_value = self._generate_complete_type_name(complete_type)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would cause a syntax error. the variable complete_type does not seem to be defined. I think you can drop the parameter final_type and put your new parameter complete_type there, then in generate_arguments() you pass complete_type=arg_value.type to _accumulate_return_arguments().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed I must have messed up with my git client. My local code is exactly what you describe. I'll push a new commit

return_arg_dict_value = self._generate_return_arg_value(
name, used_custom_scalar
)
Expand All @@ -143,6 +142,22 @@ def _accumulate_return_arguments(
)
)

def _generate_complete_type_name(
self,
complete_type: Union[GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLNonNull, GraphQLList]
) -> str:
if isinstance(complete_type, GraphQLNonNull):
if hasattr(complete_type, "of_type"):
return f"{self._generate_complete_type_name(complete_type.of_type)}!"
else:
return f"{self._generate_complete_type_name(complete_type.type)}"
if isinstance(complete_type, GraphQLList):
if hasattr(complete_type, "of_type"):
return f"[{self._generate_complete_type_name(complete_type.of_type)}]"
else:
return f"[{self._generate_complete_type_name(complete_type.type)}]"
return complete_type.name

def _generate_return_arg_value(
self, name: str, used_custom_scalar: Optional[str]
) -> Union[ast.Call, ast.Name]:
Expand Down