-
Notifications
You must be signed in to change notification settings - Fork 1
ref: small refactors #138
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
Merged
Merged
ref: small refactors #138
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,3 +192,5 @@ mise.local.toml | |
| .windsurf | ||
|
|
||
| CLAUDE.md | ||
|
|
||
| .serena | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| """Factory container for organizing Strawchemy DTO factories.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from functools import partial | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| if TYPE_CHECKING: | ||
| from strawchemy.mapper import Strawchemy | ||
| from strawchemy.strawberry.factories.aggregations import EnumDTOFactory | ||
| from strawchemy.strawberry.factories.inputs import AggregateFilterDTOFactory, BooleanFilterDTOFactory | ||
| from strawchemy.strawberry.factories.types import ( | ||
| DistinctOnFieldsDTOFactory, | ||
| InputFactory, | ||
| OrderByDTOFactory, | ||
| RootAggregateTypeDTOFactory, | ||
| TypeDTOFactory, | ||
| UpsertConflictFieldsDTOFactory, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class StrawchemyFactories: | ||
| """Container for all Strawchemy DTO factories. | ||
|
|
||
| This class encapsulates the initialization and management of all factory | ||
| instances used by Strawchemy, providing a cleaner separation of concerns | ||
| and easier testing. | ||
|
|
||
| Attributes: | ||
| aggregate_filter: Factory for aggregate filter DTOs. | ||
| order_by: Factory for order by DTOs. | ||
| distinct_on_enum: Factory for distinct on enum DTOs. | ||
| type_factory: Factory for output type DTOs. | ||
| input_factory: Factory for input type DTOs. | ||
| aggregation: Factory for root aggregate type DTOs. | ||
| enum_factory: Factory for enum DTOs. | ||
| filter_factory: Factory for boolean filter DTOs. | ||
| upsert_conflict: Factory for upsert conflict fields DTOs. | ||
| """ | ||
|
|
||
| aggregate_filter: AggregateFilterDTOFactory | ||
| order_by: OrderByDTOFactory | ||
| distinct_on_enum: DistinctOnFieldsDTOFactory | ||
| type_factory: TypeDTOFactory # type: ignore[type-arg] | ||
| input_factory: InputFactory # type: ignore[type-arg] | ||
| aggregation: RootAggregateTypeDTOFactory # type: ignore[type-arg] | ||
| enum_factory: EnumDTOFactory | ||
| filter_factory: BooleanFilterDTOFactory | ||
| upsert_conflict: UpsertConflictFieldsDTOFactory | ||
|
|
||
| @classmethod | ||
| def create(cls, mapper: Strawchemy) -> StrawchemyFactories: | ||
| """Create all factories with proper dependencies. | ||
|
|
||
| Args: | ||
| mapper: The Strawchemy instance that will own these factories. | ||
|
|
||
| Returns: | ||
| A StrawchemyFactories instance with all factories initialized. | ||
| """ | ||
| # Imports inside method to avoid circular dependencies at module load time | ||
| from strawchemy.dto.backend.strawberry import StrawberrryDTOBackend # noqa: PLC0415 | ||
| from strawchemy.strawberry.dto import MappedStrawberryGraphQLDTO # noqa: PLC0415 | ||
| from strawchemy.strawberry.factories.aggregations import EnumDTOFactory # noqa: PLC0415 | ||
| from strawchemy.strawberry.factories.enum import ( # noqa: PLC0415 | ||
| EnumDTOBackend, | ||
| UpsertConflictFieldsEnumDTOBackend, | ||
| ) | ||
| from strawchemy.strawberry.factories.inputs import ( # noqa: PLC0415 | ||
| AggregateFilterDTOFactory, | ||
| BooleanFilterDTOFactory, | ||
| ) | ||
| from strawchemy.strawberry.factories.types import ( # noqa: PLC0415 | ||
| DistinctOnFieldsDTOFactory, | ||
| InputFactory, | ||
| OrderByDTOFactory, | ||
| RootAggregateTypeDTOFactory, | ||
| TypeDTOFactory, | ||
| UpsertConflictFieldsDTOFactory, | ||
| ) | ||
|
|
||
| config = mapper.config | ||
|
|
||
| # Create backend instances | ||
| strawberry_backend = StrawberrryDTOBackend(MappedStrawberryGraphQLDTO) | ||
| enum_backend = EnumDTOBackend(config.auto_snake_case) | ||
| upsert_conflict_fields_enum_backend = UpsertConflictFieldsEnumDTOBackend( | ||
| config.inspector, config.auto_snake_case | ||
| ) | ||
|
|
||
| # Create factory instances | ||
| aggregate_filter = AggregateFilterDTOFactory(mapper) | ||
| order_by = OrderByDTOFactory(mapper) | ||
| distinct_on_enum = DistinctOnFieldsDTOFactory(config.inspector) | ||
| type_factory = TypeDTOFactory(mapper, strawberry_backend, order_by_factory=order_by) | ||
| input_factory = InputFactory(mapper, strawberry_backend) | ||
| aggregation = RootAggregateTypeDTOFactory(mapper, strawberry_backend, type_factory=type_factory) | ||
| enum_factory = EnumDTOFactory(config.inspector, enum_backend) | ||
| filter_factory = BooleanFilterDTOFactory(mapper, aggregate_filter_factory=aggregate_filter) | ||
| upsert_conflict = UpsertConflictFieldsDTOFactory(config.inspector, upsert_conflict_fields_enum_backend) | ||
|
|
||
| return cls( | ||
| aggregate_filter=aggregate_filter, | ||
| order_by=order_by, | ||
| distinct_on_enum=distinct_on_enum, | ||
| type_factory=type_factory, | ||
| input_factory=input_factory, | ||
| aggregation=aggregation, | ||
| enum_factory=enum_factory, | ||
| filter_factory=filter_factory, | ||
| upsert_conflict=upsert_conflict, | ||
| ) | ||
|
|
||
| def create_public_api(self) -> dict[str, Any]: | ||
| """Create the public API mappings for factory methods. | ||
|
|
||
| Returns: | ||
| A dictionary mapping public API names to factory methods. | ||
| """ | ||
| return { | ||
| "filter": self.filter_factory.input, | ||
| "aggregate_filter": partial(self.aggregate_filter.input, mode="aggregate_filter"), | ||
| "distinct_on": self.distinct_on_enum.decorator, | ||
| "input": self.input_factory.input, | ||
| "create_input": partial(self.input_factory.input, mode="create_input"), | ||
| "pk_update_input": partial(self.input_factory.input, mode="update_by_pk_input"), | ||
| "filter_update_input": partial(self.input_factory.input, mode="update_by_filter_input"), | ||
| "order": partial(self.order_by.input, mode="order_by"), | ||
| "type": self.type_factory.type, | ||
| "aggregate": partial(self.aggregation.type, mode="aggregate_type"), | ||
| "upsert_update_fields": self.enum_factory.input, | ||
| "upsert_conflict_fields": self.upsert_conflict.input, | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧹 Nitpick | 🔵 Trivial
Remove unused
noqadirectives.Static analysis indicates that
PLC0415is not enabled in your ruff configuration, making thesenoqacomments unnecessary. The internal imports are still valid and intentional for avoiding circular dependencies.🔎 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.14.8)
64-64: Unused
noqadirective (non-enabled:PLC0415)Remove unused
noqadirective(RUF100)
65-65: Unused
noqadirective (non-enabled:PLC0415)Remove unused
noqadirective(RUF100)
66-66: Unused
noqadirective (non-enabled:PLC0415)Remove unused
noqadirective(RUF100)
67-67: Unused
noqadirective (non-enabled:PLC0415)Remove unused
noqadirective(RUF100)
71-71: Unused
noqadirective (non-enabled:PLC0415)Remove unused
noqadirective(RUF100)
75-75: Unused
noqadirective (non-enabled:PLC0415)Remove unused
noqadirective(RUF100)
🤖 Prompt for AI Agents