Skip to content

Commit

Permalink
feat: Bump strawberry to 0.236.0 and refactor changed imports (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
bellini666 authored Jul 18, 2024
1 parent 8d997f8 commit 8c406bd
Show file tree
Hide file tree
Showing 33 changed files with 202 additions and 174 deletions.
198 changes: 99 additions & 99 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ 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.235.1"
strawberry-graphql = ">=0.236.0"

[tool.poetry.group.dev.dependencies]
Markdown = "^3.3.7"
Pygments = "^2.15.1"
channels = { version = ">=3.0.5" }
django-choices-field = "^2.2.2"
django-debug-toolbar = "^4.2.0"
django-debug-toolbar = "^3.4"
django-guardian = "^2.4.0"
django-mptt = "^0.14.0"
django-types = "^0.19.1"
Expand Down
2 changes: 1 addition & 1 deletion strawberry_django/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from strawberry import UNSET
from strawberry.annotation import StrawberryAnnotation
from strawberry.arguments import StrawberryArgument
from strawberry.types.arguments import StrawberryArgument


def argument(
Expand Down
12 changes: 6 additions & 6 deletions strawberry_django/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
from django.db.models import ForeignKey
from strawberry import LazyType, relay
from strawberry.annotation import StrawberryAnnotation
from strawberry.auto import StrawberryAuto
from strawberry.field import UNRESOLVED, StrawberryField
from strawberry.type import (
from strawberry.types import get_object_definition
from strawberry.types.auto import StrawberryAuto
from strawberry.types.base import (
StrawberryContainer,
StrawberryList,
StrawberryOptional,
StrawberryType,
WithStrawberryObjectDefinition,
get_object_definition,
)
from strawberry.union import StrawberryUnion
from strawberry.types.field import UNRESOLVED, StrawberryField
from strawberry.types.union import StrawberryUnion
from strawberry.utils.inspect import get_specialized_type_var_map

from strawberry_django.resolvers import django_resolver
Expand All @@ -30,8 +30,8 @@

if TYPE_CHECKING:
from django.db import models
from strawberry.object_type import StrawberryObjectDefinition
from strawberry.types import Info
from strawberry.types.object_type import StrawberryObjectDefinition
from typing_extensions import Literal, Self

from strawberry_django.type import StrawberryDjangoDefinition
Expand Down
6 changes: 3 additions & 3 deletions strawberry_django/fields/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
if TYPE_CHECKING:
from graphql.pyutils import AwaitableOrValue
from strawberry import BasePermission
from strawberry.arguments import StrawberryArgument
from strawberry.extensions.field_extension import (
FieldExtension,
SyncExtensionResolver,
)
from strawberry.field import _RESOLVER_TYPE, StrawberryField
from strawberry.relay.types import NodeIterableType
from strawberry.unset import UnsetType
from strawberry.types.arguments import StrawberryArgument
from strawberry.types.field import _RESOLVER_TYPE, StrawberryField
from strawberry.types.unset import UnsetType
from typing_extensions import Literal, Self

from strawberry_django.utils.typing import (
Expand Down
4 changes: 2 additions & 2 deletions strawberry_django/fields/filter_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from strawberry import UNSET
from strawberry.annotation import StrawberryAnnotation
from strawberry.exceptions import MissingArgumentsAnnotationsError
from strawberry.field import StrawberryField
from strawberry.types.field import StrawberryField
from strawberry.types.fields.resolver import ReservedName, StrawberryResolver
from typing_extensions import Self

Expand All @@ -22,8 +22,8 @@
from collections.abc import Callable, MutableMapping

from strawberry.extensions.field_extension import FieldExtension
from strawberry.field import _RESOLVER_TYPE, T
from strawberry.types import Info
from strawberry.types.field import _RESOLVER_TYPE, T


QUERYSET_PARAMSPEC = ReservedName("queryset")
Expand Down
2 changes: 1 addition & 1 deletion strawberry_django/fields/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from django.db.models import Field, Model, fields
from django.db.models.fields import files, json, related, reverse_related
from strawberry import UNSET, relay
from strawberry.enum import EnumValueDefinition
from strawberry.file_uploads.scalars import Upload
from strawberry.scalars import JSON
from strawberry.types.enum import EnumValueDefinition
from strawberry.utils.str_converters import capitalize_first, to_camel_case

from strawberry_django import filters
Expand Down
9 changes: 5 additions & 4 deletions strawberry_django/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import strawberry
from django.db.models import Q, QuerySet
from strawberry import UNSET, relay
from strawberry.field import StrawberryField, field
from strawberry.tools import create_type
from strawberry.type import WithStrawberryObjectDefinition, has_object_definition
from strawberry.unset import UnsetType
from strawberry.types import has_object_definition
from strawberry.types.base import WithStrawberryObjectDefinition
from strawberry.types.field import StrawberryField, field
from strawberry.types.unset import UnsetType
from typing_extensions import Self, assert_never, dataclass_transform

from strawberry_django.fields.filter_order import (
Expand All @@ -47,8 +48,8 @@
from types import FunctionType

from django.db.models import Model
from strawberry.arguments import StrawberryArgument
from strawberry.types import Info
from strawberry.types.arguments import StrawberryArgument


T = TypeVar("T")
Expand Down
6 changes: 4 additions & 2 deletions strawberry_django/integrations/guardian.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
import dataclasses
import weakref
from typing import Optional, Union, cast
from typing import Optional, Type, Union, cast

from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
Expand All @@ -24,7 +24,9 @@ class ObjectPermissionModels:
group: GroupObjectPermissionBase


def get_object_permission_models(model: models.Model):
def get_object_permission_models(
model: Union[models.Model, Type[models.Model]],
) -> ObjectPermissionModels:
return ObjectPermissionModels(
user=cast(UserObjectPermissionBase, get_user_obj_perms_model(model)),
group=cast(GroupObjectPermissionBase, get_group_obj_perms_model(model)),
Expand Down
11 changes: 7 additions & 4 deletions strawberry_django/mutations/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.db import models, transaction
from strawberry import UNSET, relay
from strawberry.annotation import StrawberryAnnotation
from strawberry.field import UNRESOLVED
from strawberry.types.field import UNRESOLVED
from strawberry.utils.str_converters import capitalize_first, to_camel_case
from typing_extensions import Annotated

Expand All @@ -33,10 +33,13 @@

if TYPE_CHECKING:
from graphql.pyutils import AwaitableOrValue
from strawberry.arguments import StrawberryArgument
from strawberry.type import StrawberryType, WithStrawberryObjectDefinition
from strawberry.types import Info
from strawberry.types.types import StrawberryObjectDefinition
from strawberry.types.arguments import StrawberryArgument
from strawberry.types.base import (
StrawberryObjectDefinition,
StrawberryType,
WithStrawberryObjectDefinition,
)
from typing_extensions import Literal, Self


Expand Down
2 changes: 1 addition & 1 deletion strawberry_django/mutations/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from strawberry.field_extensions import InputMutationExtension
from strawberry.permission import BasePermission
from strawberry.types.fields.resolver import StrawberryResolver
from strawberry.unset import UNSET, UnsetType
from strawberry.types.unset import UNSET, UnsetType
from typing_extensions import Literal

from .fields import (
Expand Down
23 changes: 18 additions & 5 deletions strawberry_django/mutations/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Callable,
Iterable,
List,
Type,
TypeVar,
cast,
overload,
Expand Down Expand Up @@ -262,7 +263,10 @@ def prepare_create_update(
(ParsedObject, str),
):
value, value_data = _parse_data( # noqa: PLW2901
info, field.related_model, value, key_attr=key_attr
info,
cast(Type[Model], field.related_model),
value,
key_attr=key_attr,
)
if value is None and not value_data:
value = None # noqa: PLW2901
Expand Down Expand Up @@ -508,7 +512,7 @@ def update_field(info: Info, instance: Model, field: models.Field, value: Any):
and isinstance(field, models.ForeignObject)
and not isinstance(value, Model)
):
value, data = _parse_pk(value, field.related_model)
value, data = _parse_pk(value, cast(Type[Model], field.related_model))

field.save_form_data(instance, value)
# If data was passed to the foreign key, update it recursively
Expand Down Expand Up @@ -574,7 +578,9 @@ def update_m2m(
existing = set(manager.all())
need_remove_cache = need_remove_cache or bool(values)
for v in values:
obj, data = _parse_data(info, manager.model, v, key_attr=key_attr)
obj, data = _parse_data(
info, cast(Type[Model], manager.model), v, key_attr=key_attr
)
if obj:
data.pop(key_attr, None)
through_defaults = data.pop("through_defaults", {})
Expand Down Expand Up @@ -632,7 +638,12 @@ def update_m2m(
else:
need_remove_cache = need_remove_cache or bool(value.add)
for v in value.add or []:
obj, data = _parse_data(info, manager.model, v, key_attr=key_attr)
obj, data = _parse_data(
info,
cast(Type[Model], manager.model),
v,
key_attr=key_attr,
)
if obj and data:
data.pop(key_attr, None)
if full_clean:
Expand All @@ -653,7 +664,9 @@ def update_m2m(

need_remove_cache = need_remove_cache or bool(value.remove)
for v in value.remove or []:
obj, data = _parse_data(info, manager.model, v, key_attr=key_attr)
obj, data = _parse_data(
info, cast(Type[Model], manager.model), v, key_attr=key_attr
)
data.pop(key_attr, None)
assert not data
to_remove.append(obj)
Expand Down
9 changes: 5 additions & 4 deletions strawberry_django/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
from graphql.type.definition import GraphQLResolveInfo, get_named_type
from strawberry import relay
from strawberry.extensions import SchemaExtension
from strawberry.lazy_type import LazyType
from strawberry.object_type import StrawberryObjectDefinition
from strawberry.relay.utils import SliceMetadata
from strawberry.schema.schema import Schema
from strawberry.schema.schema_converter import get_arguments
from strawberry.type import StrawberryContainer, get_object_definition
from strawberry.types import get_object_definition
from strawberry.types.base import StrawberryContainer
from strawberry.types.info import Info
from strawberry.types.lazy_type import LazyType
from strawberry.types.object_type import StrawberryObjectDefinition
from typing_extensions import assert_never, assert_type

from strawberry_django.fields.types import resolve_model_field_name
Expand Down Expand Up @@ -74,7 +75,7 @@
)

if TYPE_CHECKING:
from strawberry.field import StrawberryField # noqa: I001
from strawberry.types.field import StrawberryField # noqa: I001
from strawberry.types.execution import ExecutionContext
from strawberry.utils.await_maybe import AwaitableOrValue
from django.contrib.contenttypes.fields import GenericRelation
Expand Down
9 changes: 5 additions & 4 deletions strawberry_django/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
from django.db.models import F, OrderBy, QuerySet
from graphql.language.ast import ObjectValueNode
from strawberry import UNSET
from strawberry.field import StrawberryField, field
from strawberry.type import WithStrawberryObjectDefinition, has_object_definition
from strawberry.unset import UnsetType
from strawberry.types import has_object_definition
from strawberry.types.base import WithStrawberryObjectDefinition
from strawberry.types.field import StrawberryField, field
from strawberry.types.unset import UnsetType
from strawberry.utils.str_converters import to_camel_case
from typing_extensions import Self, dataclass_transform

Expand All @@ -34,8 +35,8 @@

if TYPE_CHECKING:
from django.db.models import Model
from strawberry.arguments import StrawberryArgument
from strawberry.types import Info
from strawberry.types.arguments import StrawberryArgument

_T = TypeVar("_T")
_QS = TypeVar("_QS", bound="QuerySet")
Expand Down
4 changes: 2 additions & 2 deletions strawberry_django/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from django.db import DEFAULT_DB_ALIAS
from django.db.models import Count, Window
from django.db.models.functions import RowNumber
from strawberry.arguments import StrawberryArgument
from strawberry.types import Info
from strawberry.unset import UNSET, UnsetType
from strawberry.types.arguments import StrawberryArgument
from strawberry.types.unset import UNSET, UnsetType
from typing_extensions import Self

from strawberry_django.fields.base import StrawberryDjangoFieldBase
Expand Down
6 changes: 3 additions & 3 deletions strawberry_django/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
FieldExtension,
SyncExtensionResolver,
)
from strawberry.field import StrawberryField
from strawberry.schema_directive import Location
from strawberry.type import StrawberryList, StrawberryOptional
from strawberry.types.base import StrawberryList, StrawberryOptional
from strawberry.types.field import StrawberryField
from strawberry.types.info import Info
from strawberry.union import StrawberryUnion
from strawberry.types.union import StrawberryUnion
from typing_extensions import Literal, assert_never

from strawberry_django.auth.utils import aget_current_user, get_current_user
Expand Down
3 changes: 2 additions & 1 deletion strawberry_django/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from strawberry import relay
from strawberry.relay.exceptions import NodeIDAnnotationError
from strawberry.relay.types import NodeIterableType
from strawberry.type import StrawberryContainer, get_object_definition
from strawberry.types import get_object_definition
from strawberry.types.base import StrawberryContainer
from strawberry.types.info import Info
from strawberry.utils.await_maybe import AwaitableOrValue
from typing_extensions import Literal, Self
Expand Down
7 changes: 4 additions & 3 deletions strawberry_django/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
from strawberry.exceptions import (
MissingFieldAnnotationError,
)
from strawberry.field import StrawberryField
from strawberry.private import is_private
from strawberry.type import WithStrawberryObjectDefinition, get_object_definition
from strawberry.types import get_object_definition
from strawberry.types.base import WithStrawberryObjectDefinition
from strawberry.types.field import StrawberryField
from strawberry.types.private import is_private
from strawberry.utils.deprecations import DeprecatedDescriptor
from typing_extensions import Literal, Self, dataclass_transform

Expand Down
10 changes: 5 additions & 5 deletions strawberry_django/utils/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

from django.db.models.query import Prefetch, QuerySet
from django.db.models.sql.where import WhereNode
from strawberry.lazy_type import LazyType
from strawberry.type import (
from strawberry.types import has_object_definition
from strawberry.types.base import (
StrawberryContainer,
StrawberryObjectDefinition,
StrawberryType,
StrawberryTypeVar,
has_object_definition,
)
from strawberry.types.types import StrawberryObjectDefinition
from strawberry.union import StrawberryUnion
from strawberry.types.lazy_type import LazyType
from strawberry.types.union import StrawberryUnion
from strawberry.utils.str_converters import to_camel_case
from typing_extensions import assert_never

Expand Down
4 changes: 2 additions & 2 deletions strawberry_django/utils/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from django.db.models.expressions import BaseExpression, Combinable
from graphql.type.definition import GraphQLResolveInfo
from strawberry.annotation import StrawberryAnnotation
from strawberry.auto import StrawberryAuto
from strawberry.type import (
from strawberry.types.auto import StrawberryAuto
from strawberry.types.base import (
StrawberryContainer,
StrawberryType,
WithStrawberryObjectDefinition,
Expand Down
3 changes: 2 additions & 1 deletion tests/auth/test_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import strawberry
from django.contrib.auth.models import Group, User
from strawberry.type import StrawberryList, get_object_definition
from strawberry.types import get_object_definition
from strawberry.types.base import StrawberryList

import strawberry_django
from strawberry_django import DjangoModelType
Expand Down
Loading

0 comments on commit 8c406bd

Please sign in to comment.