-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Optional Pagination #168
Optional Pagination #168
Changes from 7 commits
a3e6b9a
711230a
f6d0b9a
10aa828
355f969
dbc0c3e
d12e078
49a69b8
140bc65
a2e5da0
61a8d01
0fe7cd2
4b1728a
9a1f133
02ee627
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Release type: minor | ||
|
||
Add an optional function to exclude relationships from relay pagination and use traditional strawberry lists. | ||
Default behavior preserves original behavior for backwords compatibilty. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from strawberry.scalars import JSON as StrawberryJSON | ||
from strawberry.type import StrawberryOptional | ||
from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper | ||
from strawberry_sqlalchemy_mapper.relay import exclude_relay | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -263,6 +264,32 @@ class Lawyer: | |
assert {"Employee", "Lawyer"} == {t.__name__ for t in additional_types} | ||
|
||
|
||
def test_exclude_relay(employee_and_department_tables, mapper): | ||
Employee, Department = employee_and_department_tables | ||
Department.employees = exclude_relay(Department.employees) | ||
|
||
@mapper.type(Employee) | ||
class Employee: | ||
pass | ||
|
||
@mapper.type(Department) | ||
class Department: | ||
pass | ||
|
||
mapper.finalize() | ||
additional_types = list(mapper.mapped_types.values()) | ||
assert len(additional_types) == 2 | ||
mapped_employee_type = additional_types[0] | ||
assert mapped_employee_type.__name__ == "Employee" | ||
mapped_department_type = additional_types[1] | ||
assert mapped_department_type.__name__ == "Department" | ||
assert len(mapped_department_type.__strawberry_definition__._fields) == 3 | ||
department_type_fields = mapped_department_type.__strawberry_definition__._fields | ||
name = next(iter(filter(lambda f: f.name == "employees", department_type_fields))) | ||
assert type(name.type) != StrawberryOptional | ||
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. @fruitymedley, I believe the comparison should be done using I came across a couple of instances in the code that confirm this pattern: Here, we're using What do you think? |
||
assert type(name.type) == List[mapped_employee_type] | ||
|
||
|
||
def test_type_relationships(employee_and_department_tables, mapper): | ||
Employee, _ = employee_and_department_tables | ||
|
||
|
@@ -297,8 +324,7 @@ class Department: | |
@strawberry.type | ||
class Query: | ||
@strawberry.field | ||
def departments(self) -> Department: | ||
... | ||
def departments(self) -> Department: ... | ||
|
||
mapper.finalize() | ||
schema = strawberry.Schema(query=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.
I wonder if this would be better defined in
mapper.type
as an argument?Also, the name itself IMO implies you are excluding relay functionality, which is not totally true. My suggestion would be do the argument and call it
map_relations_as_list: bool = True
, in which you can opt-out asFalse
(would be even better to be the other way around, but then it would be a breaking change)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 could see a situation in which a type might have both relay and list. Would it make sense to add a class property in the same vein as
__exclude__
?