Skip to content

Commit 015d196

Browse files
committed
resolve circular dependencies
1 parent cff4a0a commit 015d196

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

api/types/type_organization.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from __future__ import annotations
2-
3-
from typing import Any, List, Optional
1+
from typing import TYPE_CHECKING, Annotated, Any, List, Optional
42

53
import strawberry
64
import strawberry_django
@@ -10,6 +8,9 @@
108
from api.models import Organization
119
from api.types.base_type import BaseType
1210

11+
if TYPE_CHECKING:
12+
from authorization.types import TypeOrganizationMembership
13+
1314

1415
@strawberry_django.filter(Organization)
1516
class OrganizationFilter:
@@ -123,7 +124,11 @@ def members_count(self, info: Info) -> int:
123124
return 0
124125

125126
@strawberry.field(description="Members in this organization")
126-
def members(self, info: Info) -> List["TypeOrganizationMembership"]:
127+
def members(
128+
self, info: Info
129+
) -> List[
130+
Annotated["TypeOrganizationMembership", strawberry.lazy("authorization.types")]
131+
]:
127132
"""Get members in this organization."""
128133
try:
129134
from authorization.models import OrganizationMembership
@@ -137,7 +142,3 @@ def members(self, info: Info) -> List["TypeOrganizationMembership"]:
137142
return TypeOrganizationMembership.from_django_list(queryset)
138143
except Exception:
139144
return []
140-
141-
142-
# Import at the end to avoid circular imports but make it available for string resolution
143-
from authorization.types import TypeOrganizationMembership # noqa: E402

api/types/type_user.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from __future__ import annotations
2-
3-
from typing import List, Optional
1+
from typing import TYPE_CHECKING, Annotated, List, Optional
42

53
import strawberry
64
import strawberry_django
@@ -9,6 +7,9 @@
97
from api.types.base_type import BaseType
108
from authorization.models import OrganizationMembership, Role, User
119

10+
if TYPE_CHECKING:
11+
from authorization.types import TypeOrganizationMembership
12+
1213

1314
@strawberry_django.filter(User)
1415
class UserFilter:
@@ -50,7 +51,11 @@ class TypeUser(BaseType):
5051
"""Type for user."""
5152

5253
@strawberry.field
53-
def organization_memberships(self) -> List["TypeOrganizationMembership"]:
54+
def organization_memberships(
55+
self,
56+
) -> List[
57+
Annotated["TypeOrganizationMembership", strawberry.lazy("authorization.types")]
58+
]:
5459
"""Get organization memberships for this user."""
5560
try:
5661
from authorization.types import TypeOrganizationMembership
@@ -74,7 +79,3 @@ def full_name(self) -> str:
7479
return last_name
7580
else:
7681
return getattr(self, "username", "")
77-
78-
79-
# Import at the end to avoid circular imports but make it available for string resolution
80-
from authorization.types import TypeOrganizationMembership # noqa: E402

0 commit comments

Comments
 (0)