I'm using strawberry-graphql
in python, and have a query that returns a list of User
@strawberry.type
class User:
email: str
name: str
def get_user():
items = get_from_database()
return items
@strawberry.type
class Query:
all_user: List[User] = strawberry.field(resolver=get_user)
schema = strawberry.Schema(Query)
It works fine, but I want some additional attributes like total_item
:
def get_user():
items = get_from_database()
return {
'items': items
'total_item': len(items)
}
In above code, Strawberry converts the dict to a string, so It didn't work. I tried to create schemas:
@strawberry.type
class User:
email: str
name: str
@strawberry.type
class GetUserResult:
items: List[User]
item_count: int
def get_user():
items = get_from_database()
return GetUserResult(
items = items
item_count = len(items)
)
But it says a query must return an iterable (Expected Iterable, but did not find one for field 'Query.allUser'.
).
Is there any way around?