Skip to content

Commit

Permalink
feat: Nested optimization for lists and connections
Browse files Browse the repository at this point in the history
  • Loading branch information
bellini666 committed Jun 2, 2024
1 parent 41a00ec commit 74e9f84
Show file tree
Hide file tree
Showing 19 changed files with 642 additions and 353 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ jobs:
fail-fast: false
matrix:
django-version:
- 3.2.*
- 4.0.*
- 4.1.*
- 4.2.*
- 5.0.*
python-version:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: check-xml
- id: check-symlinks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.5
rev: v0.4.7
hooks:
- id: ruff-format
- id: ruff
Expand Down
449 changes: 226 additions & 223 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
]
Expand All @@ -39,7 +36,7 @@ django = ">=3.2"
asgiref = ">=3.8"
django-choices-field = { version = ">=2.2.2", optional = true }
django-debug-toolbar = { version = ">=3.4", optional = true }
strawberry-graphql = ">=0.227.1"
strawberry-graphql = ">=0.234.0"

[tool.poetry.group.dev.dependencies]
Markdown = "^3.3.7"
Expand Down
13 changes: 10 additions & 3 deletions strawberry_django/fields/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
from strawberry_django.ordering import ORDER_ARG, StrawberryDjangoFieldOrdering
from strawberry_django.pagination import StrawberryDjangoPagination
from strawberry_django.permissions import filter_with_perms
from strawberry_django.queryset import run_type_get_queryset
from strawberry_django.queryset import get_queryset_config, run_type_get_queryset
from strawberry_django.relay import resolve_model_nodes
from strawberry_django.resolvers import (
default_qs_hook,
django_getattr,
django_resolver,
resolve_base_manager,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -153,6 +154,7 @@ def get_result(
args: list[Any],
kwargs: dict[str, Any],
) -> AwaitableOrValue[Any]:
# We will aways have an info as this field is not basic
is_awaitable = False

if self.base_resolver is not None:
Expand Down Expand Up @@ -222,7 +224,7 @@ async def async_resolver():
resolved = await result # type: ignore

if isinstance(resolved, BaseManager):
resolved = resolved.all()
resolved = resolve_base_manager(resolved)

if isinstance(resolved, models.QuerySet):
if "info" not in kwargs:
Expand All @@ -237,7 +239,8 @@ async def async_resolver():
return async_resolver()

if isinstance(result, BaseManager):
result = result.all()
assert info is not None
result = resolve_base_manager(result)

if isinstance(result, models.QuerySet):
if "info" not in kwargs:
Expand Down Expand Up @@ -279,6 +282,10 @@ def qs_hook(qs: models.QuerySet):
return qs_hook

def get_queryset(self, queryset, info, **kwargs):
qs_config = get_queryset_config(queryset)
if qs_config.optimizer_get_queryset_did_run:
return queryset

queryset = run_type_get_queryset(queryset, self.django_type, info)
queryset = super().get_queryset(
filter_with_perms(queryset, info), info, **kwargs
Expand Down
15 changes: 2 additions & 13 deletions strawberry_django/fields/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
Union,
)

import django
import strawberry
from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
from django.db.models import Field, Model, fields
Expand Down Expand Up @@ -239,13 +238,15 @@ def __hash__(self):
fields.IntegerField: int,
fields.PositiveIntegerField: int,
fields.PositiveSmallIntegerField: int,
fields.PositiveBigIntegerField: int,
fields.SlugField: str,
fields.SmallAutoField: strawberry.ID,
fields.SmallIntegerField: int,
fields.TextField: str,
fields.TimeField: datetime.time,
fields.URLField: str,
fields.UUIDField: uuid.UUID,
json.JSONField: JSON,
files.FileField: DjangoFileType,
files.ImageField: DjangoImageType,
related.ForeignKey: DjangoModelType,
Expand All @@ -256,18 +257,6 @@ def __hash__(self):
reverse_related.OneToOneRel: DjangoModelType,
}

if hasattr(fields, "NullBooleanField"):
# NullBooleanField was deprecated and will soon be removed
field_type_map[fields.NullBooleanField] = Optional[bool] # type: ignore

if django.VERSION >= (3, 1):
field_type_map.update(
{
json.JSONField: JSON,
fields.PositiveBigIntegerField: int,
},
)

try:
from django.contrib.gis import geos
from django.contrib.gis.db import models as geos_fields
Expand Down
Loading

0 comments on commit 74e9f84

Please sign in to comment.