Closed
Description
Hi! There is an example code:
class Photo(graphene.ObjectTypet):
id = graphene.ID()
url = graphene.String()
fileName = graphene.String()
extension = graphene.String()
class User(graphene.ObjectTypet):
_id = graphene.ID()
name = graphene.String()
photos = graphene.List(Photo)
class Query(graphene.ObjectType):
user = graphene.Field(User, dict(_id=graphene.String(required=True)))
async def resolve_user(self, info, _id):
user = await db.users.find_one(dict(_id=_id))
# do the simple filted
resolved_fileds = {f: user[f]
for f in User._meta.fields}
user = User(**resolved_fileds) if user else None
return user
The result is
{
"data": {
"user": {
"Id": "1",
"name": "Test User",
"photos": [
{
"id": null,
"fileName": null
}
]
}
}
}
Field "photos" not initialized in init. In argument "photos" I got just list with dicts. I know that I can to this serialization by myself, but maybe it's already implemented?