-
-
Notifications
You must be signed in to change notification settings - Fork 34
Option to always "use_list" and not make relay Connections #257
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 all commits
87884e4
7127a2d
c83f3fe
d97e6c5
ce24580
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,6 @@ | ||
| Release type: minor | ||
|
|
||
| Added a new optional constructor parameter to always use lists instead of relay Connections for relationships. Defaults to False, maintaining current functionality. If set to True, all relationships will be handled as lists. | ||
|
|
||
| Example: | ||
| mapper = StrawberrySQLAlchemyMapper(always_use_list=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,6 +204,10 @@ class StrawberrySQLAlchemyMapper(Generic[BaseModelType]): | |
| #: for a given (polymorphic base) model | ||
| model_to_interface_name: Callable[[Type[BaseModelType]], str] | ||
|
|
||
| #: If set to true, don't create connections for list type | ||
| #: relationships | ||
| always_use_list: bool | ||
|
|
||
| #: Default mapping from sqlalchemy types to strawberry types | ||
| _default_sqlalchemy_type_to_strawberry_type_map: Dict[ | ||
| Type[TypeEngine], Union[Type[Any], SkipTypeSentinelT] | ||
|
|
@@ -251,12 +255,14 @@ def __init__( | |
| extra_sqlalchemy_type_to_strawberry_type_map: Optional[ | ||
| Mapping[Type[TypeEngine], Type[Any]] | ||
| ] = None, | ||
Ckk3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| always_use_list: Optional[bool] = False, | ||
| ) -> None: | ||
| if model_to_type_name is None: | ||
| model_to_type_name = self._default_model_to_type_name | ||
| self.model_to_type_name = model_to_type_name | ||
| if model_to_interface_name is None: | ||
| model_to_interface_name = self._default_model_to_interface_name | ||
| self.always_use_list = always_use_list or False | ||
| self.model_to_interface_name = model_to_interface_name | ||
| self.sqlalchemy_type_to_strawberry_type_map = ( | ||
| self._default_sqlalchemy_type_to_strawberry_type_map.copy() | ||
|
|
@@ -401,7 +407,7 @@ def _convert_relationship_to_strawberry_type( | |
| self._related_type_models.add(relationship_model) | ||
| if relationship.uselist: | ||
| # Use list if excluding relay pagination | ||
| if use_list: | ||
| if use_list or self.always_use_list: | ||
|
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. todo (blocking)
Author
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. I agree. When I run
Author
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. I've never used tox or poetry before so please let me know if I'm doing something wrong.
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. @gabor-lbl Dont need to bother with this, if it runs with
Author
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. What do I need to install to run pytest? I ran pytest on its own and it needed testing.postgres. I installed that but it still won't run:
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. @gabor-lbl Oh you need to have a postgres soo it can create the database. If you prefer, we can also talk in strawberry discord server, you can find me there as
Author
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. Ok thanks - I added a new test to check the always_use_list param.
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. Thanks @gabor-lbl , I'll review it later |
||
| return List[ForwardRef(type_name)] # type: ignore | ||
|
|
||
| return self._connection_type_for(type_name) | ||
|
|
@@ -669,7 +675,7 @@ def connection_resolver_for( | |
| passed from the GraphQL query to the database query. | ||
| """ | ||
| relationship_resolver = self.relationship_resolver_for(relationship) | ||
| if relationship.uselist and not use_list: | ||
| if relationship.uselist and not use_list and not self.always_use_list: | ||
| return self.make_connection_wrapper_resolver( | ||
| relationship_resolver, | ||
| relationship, | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.