-
-
Notifications
You must be signed in to change notification settings - Fork 146
Add support for strawberry.Maybe type in filter processing #805
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,6 +142,43 @@ def test_resolve_value(value, resolved): | |||||||||||||||||||||||||||||
| assert resolve_value(value) == resolved | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def test_resolve_value_maybe(): | ||||||||||||||||||||||||||||||
| """Test that strawberry.Maybe type is properly handled in resolve_value.""" | ||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||
| from strawberry import Maybe | ||||||||||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||||||||||
| pytest.skip("strawberry.Maybe is not available in this version") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Test Maybe with a value | ||||||||||||||||||||||||||||||
| maybe_with_value = Maybe(value="test_string") | ||||||||||||||||||||||||||||||
| assert resolve_value(maybe_with_value) == "test_string" | ||||||||||||||||||||||||||||||
|
Comment on lines
+153
to
+154
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: I think all of those can be parametrized on pyright. Will make the implementation cleaner |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Test Maybe with None | ||||||||||||||||||||||||||||||
| maybe_none = Maybe(value=None) | ||||||||||||||||||||||||||||||
| assert resolve_value(maybe_none) is None | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Test Maybe with nested types | ||||||||||||||||||||||||||||||
| maybe_enum = Maybe(value=Version.TWO) | ||||||||||||||||||||||||||||||
| assert resolve_value(maybe_enum) == Version.TWO.value | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| maybe_gid = Maybe(value=GlobalID("FruitNode", "42")) | ||||||||||||||||||||||||||||||
| assert resolve_value(maybe_gid) == "42" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Test Maybe in a list | ||||||||||||||||||||||||||||||
| maybe_list = [ | ||||||||||||||||||||||||||||||
| Maybe(value=1), | ||||||||||||||||||||||||||||||
| Maybe(value="test"), | ||||||||||||||||||||||||||||||
| Maybe(value=None), | ||||||||||||||||||||||||||||||
| Maybe(value=Version.ONE), | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| resolved_list = resolve_value(maybe_list) | ||||||||||||||||||||||||||||||
| assert resolved_list == [1, "test", None, Version.ONE.value] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Test nested Maybe | ||||||||||||||||||||||||||||||
| nested_maybe = Maybe(value=Maybe(value="nested")) | ||||||||||||||||||||||||||||||
| assert resolve_value(nested_maybe) == "nested" | ||||||||||||||||||||||||||||||
|
Comment on lines
+181
to
+183
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider adding a test for lists containing nested Maybes. Add a test with a list containing nested Maybe instances, such as [Maybe(value=Maybe(value="foo")), Maybe(value=None)], to verify resolve_value correctly handles nested Maybes.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def test_filter_field_missing_prefix(): | ||||||||||||||||||||||||||||||
| with pytest.raises( | ||||||||||||||||||||||||||||||
| MissingFieldArgumentError, match=r".*\"prefix\".*\"field_method\".*" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.
suggestion: ditto