Untitled

 avatar
unknown
plain_text
5 months ago
9.5 kB
5
Indexable
I am getting this error:
raise UnresolvedFieldTypeError(type_definition, field)
strawberry.exceptions.unresolved_field_type.UnresolvedFieldTypeError: Could not resolve the type of 'group_relation'. Check that the class is accessible from the global module scope.
group.py (model)
from datetime import datetime
from typing import List

from sqlalchemy import (
    TIMESTAMP,
    BigInteger,
    ForeignKeyConstraint,
    Index,
    Integer,
    String,
    Text,
    text,
)
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.orm.base import Mapped

from .base import Base


class Group(Base):
    __tablename__ = "mdm_group"
    __table_args__ = (
        ForeignKeyConstraint(["STATUS_ID"], ["mdm_status.STATUS_ID"], name="STATUS_ID"),
        Index("GROUP_NAME_UNIQUE", "GROUP_NAME", unique=True),
        Index("STATUS_ID_idx", "STATUS_ID"),
    )

    id: Mapped[int] = mapped_column("GROUP_ID", Integer, primary_key=True)
    name: Mapped[str] = mapped_column("GROUP_NAME", String(255), nullable=False)
    type: Mapped[str] = mapped_column("GROUP_TYPE", String(45), nullable=False)
    version_id: Mapped[int] = mapped_column("VERSION_ID", BigInteger, nullable=False)
    status_id: Mapped[int] = mapped_column("STATUS_ID", Integer, nullable=False)
    created_date: Mapped[datetime] = mapped_column(
        "CREATED_DATE",
        TIMESTAMP,
        nullable=False,
        server_default=text("'0000-00-00 00:00:00'"),
    )
    created_by_id: Mapped[str] = mapped_column(
        "CREATED_BY_ID", String(50), nullable=False
    )
    updated_date: Mapped[datetime] = mapped_column(
        "UPDATED_DATE",
        TIMESTAMP,
        nullable=False,
        server_default=text("'0000-00-00 00:00:00'"),
    )
    updated_by_id: Mapped[str] = mapped_column(
        "UPDATED_BY_ID", String(50), nullable=False
    )
    is_deleted: Mapped[int] = mapped_column("IS_DELETED", Integer, nullable=False)
    description: Mapped[str] = mapped_column("GROUP_DESCRIPTION", Text)

    status: Mapped["Status"] = relationship("Status", back_populates="group")
    product_category: Mapped[List["ProductCategory"]] = relationship(
        "ProductCategory", uselist=True, back_populates="group"
    )
    product_subcategory: Mapped[List["ProductSubcategory"]] = relationship(
        "ProductSubcategory", uselist=True, back_populates="group"
    )
    group_relation: Mapped["GroupRelation"] = relationship(
        "GroupRelation", uselist=True, back_populates="group", foreign_keys=[id]
    )
    sub_group_relation: Mapped["GroupRelation"] = relationship(
        "GroupRelation", uselist=True, back_populates="sub_group", foreign_keys=[id],
    )
group_type.py(type):
from datetime import datetime
from typing import List, Optional, TYPE_CHECKING, Annotated

from strawberry import ID, Parent, field, type, lazy

from app.graphql.schema import Info
from app.models import Group

from .user_type import UserType
if TYPE_CHECKING:
    from .group_relation_type import GroupRelationType


@type(name="Group")
class GroupType:
    id: ID
    name: str
    type: str
    version_id: int
    status_id: int
    created_date: datetime
    created_by_id: str
    updated_date: datetime
    updated_by_id: str
    is_deleted: int
    description: str

    @field
    @staticmethod
    async def created_by(
        info: Info, parent: Parent["Group"]
    ) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.created_by_id)

    @field
    @staticmethod
    async def updated_by(
        info: Info, parent: Parent["Group"]
    ) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.updated_by_id)
    
    @field
    @staticmethod
    async def status(
        info: Info, parent: Parent["Group"]
    ) -> Optional["StatusType"]:
        return await info.context.load_status.load(parent.status_id)

    @field
    @staticmethod
    async def product_category(
        info: Info, parent: Parent["Group"]
    ) -> Optional["ProductCategoryType"]:
        return await info.context.load_product_categories.load(parent.category_id)
    
    @field
    @staticmethod
    async def product_subcategory(
        info: Info, parent: Parent["Group"]
    ) -> Optional["ProductSubcategoryType"]:
        return await info.context.load_product_subcategories.load(parent.subcategory_id)
    
    @field
    @staticmethod
    async def group_relation(
        info: Info, parent: Parent["Group"]
    ) -> List[Annotated["GroupRelationType", lazy(".group_relation_type")]]:
        return await info.context.load_group_relation.load(parent.id)
    
    @field
    @staticmethod
    async def sub_group_relation(
        info: Info, parent: Parent["Group"]
    ) -> List[Annotated["GroupRelationType", lazy(".group_relation_type")]]:
        return await info.context.load_sub_group_relation.load(parent.id)
group_relation.py(model):
from datetime import datetime
from typing import List

from sqlalchemy import TIMESTAMP, BigInteger, Integer, String, Text, text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.orm.base import Mapped

from .base import Base


class GroupRelation(Base):
    __tablename__ = "mdm_group_relation"

    id: Mapped[int] = mapped_column("GRP_REL_ID", Integer, primary_key=True)
    group_id: Mapped[int] = mapped_column("GROUP_ID", Integer, nullable=False)
    sub_group_id: Mapped[int] = mapped_column("SUB_GROUP_ID", Integer, nullable=False)
    country_id: Mapped[int] = mapped_column("COUNTRY_ID", Integer, nullable=False)
    group_rel_version_id: Mapped[int] = mapped_column(
        "GROUP_REL_VERSION_ID", BigInteger, nullable=False
    )
    sub_ta: Mapped[str] = mapped_column("SUB_TA", Text, nullable=False)
    status_id: Mapped[int] = mapped_column("STATUS_ID", Integer, nullable=False)
    is_deleted: Mapped[int] = mapped_column("IS_DELETED", Integer, nullable=False)
    created_date: Mapped[datetime] = mapped_column(
        "CREATED_DATE",
        TIMESTAMP,
        nullable=False,
        server_default=text("'0000-00-00 00:00:00'"),
    )
    created_by_id: Mapped[str] = mapped_column(
        "CREATED_BY_ID", String(50), nullable=False
    )
    updated_date: Mapped[datetime] = mapped_column(
        "UPDATED_DATE", TIMESTAMP, nullable=False
    )
    updated_by_id: Mapped[str] = mapped_column(
        "UPDATED_BY_ID", String(50), nullable=False
    )
    merged_to: Mapped[int] = mapped_column("MERGED_TO", Integer)
    group: Mapped[List["Group"]] = relationship(
        "Group", uselist=True, back_populates="group_relation", foreign_keys=[group_id]
    )
    sub_group: Mapped[List["Group"]] = relationship(
        "Group", uselist=True, back_populates="group_relation", foreign_keys=[sub_group_id]
    )
    country: Mapped["Country"] = relationship(
        "Country", uselist=True, back_populates="group_relation", foreign_keys=[country_id]
    )
    status: Mapped["Status"] = relationship(
        "Status", uselist=True, back_populates="group_relation", foreign_keys=[status_id]
    )
group_relation_type.py(type):
from datetime import datetime
from typing import List, Optional, TYPE_CHECKING, Annotated

from strawberry import ID, Parent, field, type, lazy

from app.graphql.schema import Info
from app.models import GroupRelation

from .user_type import UserType
if TYPE_CHECKING:
    from .group_type import GroupType
    from .country_type import CountryType
    from .status_type import StatusType


@type(name="GroupRelation")
class GroupRelationType:
    id: ID
    group_id: int
    sub_group_id: int
    country_id: int
    group_rel_version_id: int
    sub_ta: str
    status_id: int
    is_deleted: int
    created_date: datetime
    created_by_id: str
    updated_date: datetime
    updated_by_id: str
    merged_to: int | None

    @field
    @staticmethod
    async def created_by(
        info: Info, parent: Parent["GroupRelation"]
    ) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.created_by_id)

    @field
    @staticmethod
    async def updated_by(
        info: Info, parent: Parent["GroupRelation"]
    ) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.updated_by_id)
    
    @field
    @staticmethod
    async def group(
        info: Info, parent: Parent["GroupRelation"]
    ) -> Optional[Annotated["GroupType", lazy(".group_type")]]:
        return await info.context.load_group.load(parent.group_id)
    
    @field
    @staticmethod
    async def sub_group(
        info: Info, parent: Parent["GroupRelation"]
    ) -> Optional[Annotated["GroupType", lazy(".group_type")]]:
        return await info.context.load_group.load(parent.sub_group_id)
    
    @field
    @staticmethod
    async def country(
        info: Info, parent: Parent["GroupRelation"]
    ) -> Optional[Annotated["CountryType", lazy(".country_type")]]:
        return await info.context.load_country.load(parent.country_id)

    @field
    @staticmethod
    async def status(
        info: Info, parent: Parent["GroupRelation"]
    ) -> Optional[Annotated["StatusType", lazy(".status_type")]]:
        return await info.context.load_status.load(parent.status_id)
Editor is loading...
Leave a Comment