-
Notifications
You must be signed in to change notification settings - Fork 179
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-293-default-enum-values #533
Conversation
Codecov Report
@@ Coverage Diff @@
## master #533 +/- ##
==========================================
+ Coverage 98.21% 98.25% +0.04%
==========================================
Files 104 104
Lines 5332 5513 +181
==========================================
+ Hits 5237 5417 +180
- Misses 95 96 +1
Continue to review full report at Codecov.
|
ariadne/executable_schema.py
Outdated
@@ -37,8 +54,103 @@ def make_executable_schema( | |||
|
|||
assert_valid_schema(schema) | |||
|
|||
for type_name, field_name, arg, _ in find_enum_values_in_schema(schema): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code block should live in separate validate_schema_enum_values
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ariadne/executable_schema.py
Outdated
return schema | ||
|
||
|
||
def join_type_defs(type_defs: List[str]) -> str: | ||
return "\n\n".join(t.strip() for t in type_defs) | ||
|
||
|
||
def find_enum_values_in_schema( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets move this util somewhere else so executable_schema.py
stays at current small and sweet size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
c9478bc
to
b90e13c
Compare
ariadne/enums.py
Outdated
return routes | ||
|
||
|
||
def is_invalid_enum_value(field: Union[GraphQLInputField, GraphQLArgument]) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this function under validate_schema_enum_values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ariadne/enums.py
Outdated
return field.default_value is Undefined and field.ast_node.default_value is not None | ||
|
||
|
||
def validate_schema_enum_values(schema: GraphQLSchema) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this function before find_enum_values_in_schema
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ariadne/executable_schema.py
Outdated
@@ -22,23 +26,42 @@ def make_executable_schema( | |||
|
|||
ast_document = parse(type_defs) | |||
schema = build_ast_schema(ast_document) | |||
cleaned_bindables: List[SchemaBindable] = clean_bindables(*bindables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be inlined in for bindable in clean_bindables(*bindables):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree, but please notice, that, clean_binables
(now flat_binables
) are also passed in repair_default_enum_values
. That is the reason of extraction of that variable.
ariadne/executable_schema.py
Outdated
|
||
return schema | ||
|
||
|
||
def join_type_defs(type_defs: List[str]) -> str: | ||
return "\n\n".join(t.strip() for t in type_defs) | ||
|
||
|
||
def clean_bindables( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def clean_bindables( | |
def flatten_bindables( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/test_enums.py
Outdated
""" | ||
query = QueryType() | ||
|
||
def resolv(*_, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def resolv(*_, value): | |
def resolve_test_enum(*_, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (for all lines, where it occurs).
tests/test_enums.py
Outdated
assert result.data["complex"] | ||
|
||
|
||
def test_input_exc_schema_should_raise_an_exception_if_undefined_enum_flat_input(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_input_exc_schema_should_raise_an_exception_if_undefined_enum_flat_input(): | |
def test_input_exc_schema_raises_exception_for_undefined_enum_value_in_flat_input(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/test_enums.py
Outdated
make_executable_schema([enum_definition, input_schema]) | ||
|
||
|
||
def test_input_exc_schema_should_raise_an_exception_if_undefined_enum_in_nested_input(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_input_exc_schema_should_raise_an_exception_if_undefined_enum_in_nested_input(): | |
def test_input_exc_schema_raises_exception_for_undefined_enum_value_in_nested_object(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/test_enums.py
Outdated
make_executable_schema([enum_definition, input_schema]) | ||
|
||
|
||
def test_input_exc_schema_should_raise_an_exception_if_undefined_enum_in_query(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_input_exc_schema_should_raise_an_exception_if_undefined_enum_in_query(): | |
def test_input_exc_schema_raises_exception_for_undefined_enum_value_in_nested_field_arg(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/test_enums.py
Outdated
assert len(undefined) == number_of_undefined_default_enum_values | ||
|
||
|
||
def test_issue_293(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test name should shortly reflect what behaviour is tested, with docstring (or plain comment) mentioning that its a regression test for issue, eg.:
def test_something():
# regression test for https://github.com/mirumee/issues/31321
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ariadne/enums.py
Outdated
def find_enum_values_in_schema( | ||
schema: GraphQLSchema, | ||
) -> Generator[Union[ArgumentWithKeys, InputFieldWithKeys], None, None]: | ||
object_types = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a biggest fan of iterating schema twice to create two lists that are then iterated over again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have refactored it a little bit, now I rely on functools
's singledispatch
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And now we iterating only once ofc ;d
cast, | ||
) | ||
from functools import reduce, singledispatch | ||
import operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this import under import enum
|
||
|
||
def get_value_from_mapping_value(mapping: Mapping[T, Any], key_list: List[T]) -> Any: | ||
return reduce(operator.getitem, key_list, mapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not run this in for
loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm no particular reason, I found reduce
more appropriate to apply collection of arguments to dict
fixes #293 #547