-
Notifications
You must be signed in to change notification settings - Fork 1
ref: mapper api overhaul #147
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
16d303b
abf6ba0
18ba6e5
5afbf12
912c82e
f972983
9fcd3ee
01276e4
dff45dc
701b55c
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 |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| from strawchemy import Strawchemy, StrawchemyAsyncRepository, StrawchemyConfig | ||
| from testapp.models import Customer, Milestone, Project, Ticket | ||
|
|
||
| strawchemy = Strawchemy(StrawchemyConfig("sqlite", repository_type=StrawchemyAsyncRepository)) | ||
| strawchemy = Strawchemy(StrawchemyConfig("sqlite", repository_type=StrawchemyAsyncRepository, include=["name"])) | ||
|
|
||
| # Ticket | ||
|
|
||
|
|
@@ -20,7 +20,7 @@ class TicketOrder: ... | |
| class TicketFilter: ... | ||
|
|
||
|
|
||
| @strawchemy.type(Ticket, include="all", filter_input=TicketFilter, order_by=TicketOrder, override=True) | ||
| @strawchemy.type(Ticket, include="all", filter_input=TicketFilter, order=TicketOrder, override=True) | ||
|
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for order_by usage in strawchemy.type() and strawchemy.field() calls
echo "=== Type decorator usage with order_by ==="
rg -nP '@strawchemy\.type\([^)]*order_by\s*=' --type=py
echo -e "\n=== Field usage with order_by ==="
rg -nP 'strawchemy\.field\([^)]*order_by\s*=' --type=py
echo -e "\n=== Type decorator usage with order= (new pattern) ==="
rg -nP '@strawchemy\.type\([^)]*order\s*=' --type=py | head -20
echo -e "\n=== Field usage with order= (new pattern) ==="
rg -nP 'strawchemy\.field\([^)]*order\s*=' --type=py | head -20Repository: gazorby/strawchemy Length of output: 3173 Update field-level API to use The type decorator has been migrated to use
Update all field-level calls to use 🤖 Prompt for AI Agents |
||
| class TicketType: ... | ||
|
|
||
|
|
||
|
|
@@ -55,7 +55,7 @@ class ProjectOrder: ... | |
| class ProjectFilter: ... | ||
|
|
||
|
|
||
| @strawchemy.type(Project, include="all", filter_input=ProjectFilter, order_by=ProjectOrder, override=True) | ||
| @strawchemy.type(Project, include="all", filter_input=ProjectFilter, order=ProjectOrder, override=True) | ||
| class ProjectType: ... | ||
|
|
||
|
|
||
|
|
@@ -66,7 +66,7 @@ class ProjectCreate: ... | |
| # Milestone | ||
|
|
||
|
|
||
| @strawchemy.type(Milestone, include="all", override=True) | ||
| @strawchemy.type(Milestone, include={"name"}, override=True, distinct_on=["age"], paginate=["projects"]) | ||
| class MilestoneType: ... | ||
|
Comment on lines
+69
to
70
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.
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,9 +3,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass, field | ||||||||||||||||||||||||||||||||||||||||||||||
| from functools import cached_property | ||||||||||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING, Any | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| from strawchemy.dto.inspectors import SQLAlchemyGraphQLInspector | ||||||||||||||||||||||||||||||||||||||||||||||
| from strawchemy.dto.types import DTOConfig, FieldIterable, IncludeFields | ||||||||||||||||||||||||||||||||||||||||||||||
| from strawchemy.repository.strawberry import StrawchemySyncRepository | ||||||||||||||||||||||||||||||||||||||||||||||
| from strawchemy.utils.strawberry import default_session_getter | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -43,17 +45,39 @@ class StrawchemyConfig: | |||||||||||||||||||||||||||||||||||||||||||||
| """Override default filters with custom filters.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| execution_options: dict[str, Any] | None = None | ||||||||||||||||||||||||||||||||||||||||||||||
| """SQLAlchemy execution options for strawberry operations.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| pagination_default_limit: int = 100 | ||||||||||||||||||||||||||||||||||||||||||||||
| """Default pagination limit when `pagination=True`.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| pagination: bool = False | ||||||||||||||||||||||||||||||||||||||||||||||
| """Enable/disable pagination on list resolvers.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| default_id_field_name: str = "id" | ||||||||||||||||||||||||||||||||||||||||||||||
| """Name for primary key fields arguments on primary key resolvers.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| deterministic_ordering: bool = True | ||||||||||||||||||||||||||||||||||||||||||||||
| """Force deterministic ordering for list resolvers.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| include: IncludeFields = "all" | ||||||||||||||||||||||||||||||||||||||||||||||
| """Globally included fields.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| exclude: FieldIterable | None = None | ||||||||||||||||||||||||||||||||||||||||||||||
| """Globally included fields.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| pagination: IncludeFields | None = None | ||||||||||||||||||||||||||||||||||||||||||||||
| """Enable/disable pagination on list resolvers.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| order_by: IncludeFields | None = None | ||||||||||||||||||||||||||||||||||||||||||||||
| """Enable/disable order by on list resolvers.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| distinct_on: IncludeFields | None = None | ||||||||||||||||||||||||||||||||||||||||||||||
| """Enable/disable order by onelist resolvers.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| pagination_default_limit: int = 100 | ||||||||||||||||||||||||||||||||||||||||||||||
| """Default pagination limit when `pagination=True`.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| pagination_default_offset: int = 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| """Default pagination offset when `pagination=True`.""" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+62
to
+65
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. Inline docstrings reference outdated API. The docstrings on lines 55 and 57 mention 🔎 Proposed fix pagination_default_limit: int = 100
- """Default pagination limit when `pagination=True`."""
+ """Default pagination limit when pagination is enabled."""
pagination_default_offset: int = 0
- """Default pagination offset when `pagination=True`."""
+ """Default pagination offset when pagination is enabled."""📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+52
to
+65
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. Fix documentation errors in field docstrings. There are two issues in the docstrings:
📝 Proposed fix include: IncludeFields = "all"
"""Globally included fields."""
exclude: FieldIterable | None = None
- """Globally included fields."""
+ """Globally excluded fields."""
pagination: IncludeFields | None = None
"""Enable/disable pagination on list resolvers."""
order_by: IncludeFields | None = None
"""Enable/disable order by on list resolvers."""
distinct_on: IncludeFields | None = None
- """Enable/disable order by onelist resolvers."""
+ """Enable/disable distinct on for list resolvers."""
pagination_default_limit: int = 100
"""Default pagination limit when `pagination=True`."""
pagination_default_offset: int = 0
"""Default pagination offset when `pagination=True`."""🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| inspector: SQLAlchemyGraphQLInspector = field(init=False) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def __post_init__(self) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||
| """Initializes the SQLAlchemyGraphQLInspector after the dataclass is created.""" | ||||||||||||||||||||||||||||||||||||||||||||||
| self.inspector = SQLAlchemyGraphQLInspector(self.dialect, filter_overrides=self.filter_overrides) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @cached_property | ||||||||||||||||||||||||||||||||||||||||||||||
| def order_config(self) -> DTOConfig: | ||||||||||||||||||||||||||||||||||||||||||||||
| return DTOConfig.from_include(self.order_by) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @cached_property | ||||||||||||||||||||||||||||||||||||||||||||||
| def distinct_on_config(self) -> DTOConfig: | ||||||||||||||||||||||||||||||||||||||||||||||
| return DTOConfig.from_include(self.distinct_on) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @cached_property | ||||||||||||||||||||||||||||||||||||||||||||||
| def pagination_config(self) -> DTOConfig: | ||||||||||||||||||||||||||||||||||||||||||||||
| return DTOConfig.from_include(self.pagination) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+83
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. 🛠️ Refactor suggestion | 🟠 Major Avoid memoizing derived configs on a mutable dataclass.
♻️ Minimal fix- `@cached_property`
+ `@property`
def order_config(self) -> DTOConfig:
return DTOConfig.from_include(self.order_by)
- `@cached_property`
+ `@property`
def distinct_on_config(self) -> DTOConfig:
return DTOConfig.from_include(self.distinct_on)
- `@cached_property`
+ `@property`
def pagination_config(self) -> DTOConfig:
return DTOConfig.from_include(self.pagination)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
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.
Fix hyphenation in configuration table.
"snake cased names" should be hyphenated as "snake-cased names" for proper English grammar.
🔎 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~2105-~2105: Use a hyphen to join words.
Context: ... | Automatically convert snake cased names to camel case in GraphQL sch...
(QB_NEW_EN_HYPHEN)
🤖 Prompt for AI Agents