Untitled
unknown
plain_text
a year ago
652 B
4
Indexable
from typing import List, Optional
from sqlalchemy.orm import Session
from app.graphql.schema import Info
from app.graphql.types.product_type import ProductType
from app.models import Product
async def products_resolver(
self, info: Info, content_type: Optional[str] = None
) -> List[ProductType]:
session: Session = info.context.session
# Ensure this matches the field name in the SQLAlchemy model
query = session.query(Product).limit(10)
# Filter by content type if provided
if content_type:
query = query.filter_by(type=content_type)
# Execute the query and return the results directly
return query.all()Editor is loading...
Leave a Comment