Skip to content

Commit

Permalink
Merge pull request #542 from GDGSNF/master
Browse files Browse the repository at this point in the history
Refactor Code Expression ✨
  • Loading branch information
abusi committed Nov 4, 2021
2 parents e4b879f + 973ec71 commit c9fc4cb
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
}
_ESCAPED_CHARACTER_REGEX = re.compile(
"|".join(
[
re.escape(sub_str)
for sub_str in sorted(
_STRING_VALUE_ESCAPED_CHARACTER_REPLACEMENTS,
key=len,
reverse=True,
)
]
re.escape(sub_str)
for sub_str in sorted(
_STRING_VALUE_ESCAPED_CHARACTER_REPLACEMENTS,
key=len,
reverse=True,
)
)
)

Expand Down Expand Up @@ -147,7 +145,7 @@ def float_value(self, tree: "Tree") -> "Tree":
tree,
Token(
"FLOAT_VALUE",
float("".join([child.value for child in tree.children])),
float("".join(child.value for child in tree.children)),
first_token.start_pos,
first_token.line,
first_token.column,
Expand Down
24 changes: 10 additions & 14 deletions tartiflette/language/validators/query/fragment_must_be_used.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@ class FragmentMustBeUsed(June2018ReleaseValidationRule):
RULE_NUMBER = "5.5.1.4"

def validate(self, path, fragments, fragment_spreads=None, **__):
errors = []

if not fragment_spreads:
fragment_spreads = []

for fragment in fragments:
if not find_nodes_by_name(fragment_spreads, fragment.name.value):
errors.append(
graphql_error_from_nodes(
message=f"Fragment < {fragment.name.value} > is never used.",
nodes=fragment,
path=path,
extensions=self._extensions,
)
)

return errors
return [
graphql_error_from_nodes(
message=f"Fragment < {fragment.name.value} > is never used.",
nodes=fragment,
path=path,
extensions=self._extensions,
)
for fragment in fragments
if not find_nodes_by_name(fragment_spreads, fragment.name.value)
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ class FragmentSpreadTargetDefined(June2018ReleaseValidationRule):
RULE_NUMBER = "5.5.2.1"

def _to_errors(self, erronous_speads, path):
errors = []
for spread_name, spreads in erronous_speads.items():
errors.append(
graphql_error_from_nodes(
message=f"Unknown Fragment for Spread < {spread_name} >.",
nodes=spreads,
path=path,
extensions=self._extensions,
)
return [
graphql_error_from_nodes(
message=f"Unknown Fragment for Spread < {spread_name} >.",
nodes=spreads,
path=path,
extensions=self._extensions,
)
return errors
for spread_name, spreads in erronous_speads.items()
]

def validate(self, path, fragments, fragment_spreads=None, **__):
erronous_speads = {}
Expand Down
22 changes: 10 additions & 12 deletions tartiflette/language/validators/query/required_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,22 @@ class RequiredArguments(June2018ReleaseValidationRule):
def _validate_arguments(
self, parent_node, schema_definition, path, message_suffix
):
errors = []
for schema_arg in schema_definition.arguments.values():
return [
graphql_error_from_nodes(
message=f"Missing mandatory argument < {schema_arg.name} > {message_suffix}",
nodes=parent_node,
path=path,
extensions=self._extensions,
)
for schema_arg in schema_definition.arguments.values()
if (
isinstance(schema_arg.graphql_type, GraphQLNonNull)
and schema_arg.default_value is None
and not find_nodes_by_name(
parent_node.arguments, schema_arg.name
)
):
errors.append(
graphql_error_from_nodes(
message=f"Missing mandatory argument < {schema_arg.name} > {message_suffix}",
nodes=parent_node,
path=path,
extensions=self._extensions,
)
)
return errors
)
]

def _validate_directive(self, path, schema, directive_node):
if not schema.has_directive(directive_node.name.value):
Expand Down
3 changes: 1 addition & 2 deletions tartiflette/types/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def __init__(
# Introspection attributes
self.interfaces: List["GraphQLInterfaceType"] = []
self.fields: List["GraphQLField"] = []
self._possible_types_set = set()
self._possible_types_set.add(self.name)
self._possible_types_set = {self.name}

def __eq__(self, other: Any) -> bool:
"""
Expand Down
24 changes: 12 additions & 12 deletions tests/functional/coercers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ async def resolve_list_field(parent, args, ctx, info):
return "SUCCESS-[{}]".format(
str(args["param"])
if not isinstance(args["param"], list)
else "-".join([str(item) for item in args["param"]])
else "-".join(str(item) for item in args["param"])
)

return "SUCCESS"


Expand All @@ -234,19 +235,18 @@ async def resolve_input_object_field(parent, args, ctx, info):
return "SUCCESS-{}"
return "SUCCESS-{}".format(
"-".join(
[
"[{}:{}]".format(
str(arg_name),
str(
arg_values
if not isinstance(arg_values, list)
else "-".join([str(arg) for arg in arg_values])
),
)
for arg_name, arg_values in args["param"].items()
]
"[{}:{}]".format(
str(arg_name),
str(
arg_values
if not isinstance(arg_values, list)
else "-".join(str(arg) for arg in arg_values)
),
)
for arg_name, arg_values in args["param"].items()
)
)

return "SUCCESS"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def resolve_a(parent_result, _args, _ctx, _info):


async def subscription_timer(parent_result, *_, **__):
for integer in range(0, 10):
for integer in range(10):
yield {"timer": integer + parent_result}
await asyncio.sleep(0.01)

Expand Down
8 changes: 5 additions & 3 deletions tests/functional/regressions/test_directives_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ async def on_argument_execution(
value,
ctx,
)
if isinstance(result, (int, float)):
if result > directive_args["limit"]:
raise ValueError(f"{result} > {directive_args['limit']}")
if (
isinstance(result, (int, float))
and result > directive_args["limit"]
):
raise ValueError(f"{result} > {directive_args['limit']}")
return result

async def on_field_execution(
Expand Down
11 changes: 6 additions & 5 deletions tests/functional/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ def is_expected(result, expected):
assert len(result["errors"]) == len(expected["errors"])
not_found = []
for expected_error in expected["errors"]:
is_found = False
for result_error in result["errors"]:
if expected_error == result_error:
is_found = True
is_found = any(
expected_error == result_error
for result_error in result["errors"]
)

if not is_found:
not_found.append(expected_error)
if not_found:
raise AssertionError(
"Following expected errors wasn't found: {}".format(
", ".join(
[str(expected_error) for expected_error in not_found]
str(expected_error) for expected_error in not_found
)
)
)

0 comments on commit c9fc4cb

Please sign in to comment.