# NIKAME GENERATED — DO NOT EDIT DIRECTLY
import strawberry
from typing import List, Optional
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from strawberry.fastapi import BaseContext

from app.db.session import get_db
from app.graphql.types import {% for model_name in models %}{{ model_name }}{% if not loop.last %}, {% endif %}{% endfor %}
from app.models.{% for model_name in models %}{{ model_name | lower }}{% if not loop.last %}, {% endif %}{% endfor %} as models

class Context(BaseContext):
    def __init__(self, db: AsyncSession):
        self.db = db

@strawberry.type
class Query:
    {% for model_name in models %}
    @strawberry.field
    async def get_{{ model_name | lower }}s(self, info: strawberry.Info) -> List[{{ model_name }}]:
        db: AsyncSession = info.context.db
        result = await db.execute(select(models.{{ model_name }}))
        return result.scalars().all()

    @strawberry.field
    async def get_{{ model_name | lower }}(self, info: strawberry.Info, id: int) -> Optional[{{ model_name }}]:
        db: AsyncSession = info.context.db
        result = await db.execute(select(models.{{ model_name }}).where(models.{{ model_name }}.id == id))
        return result.scalar_one_or_none()
    {% endfor %}

schema = strawberry.Schema(query=Query)
