ObjectType resolving fields from dicts or objects
See original GitHub issueHi! 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?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
ObjectType - Graphene-Python
ObjectType ¶. A Graphene ObjectType is the building block used to define the relationship between Fields in your Schema and how their data...
Read more >Python dictionary from an object's fields - Stack Overflow
I thought I'd take some time to show you how you can translate an object to dict via dict(obj) . class A(object): d...
Read more >ObjectTypes — Graphene 1.0 documentation - Read the Docs
A resolver is a method that resolves certain fields within an ObjectType . If not specified otherwise, the resolver of a field is...
Read more >Resolvers - Ariadne GraphQL
To bind resolvers to schema, Ariadne uses a special ObjectType class that is ... a field an alias for a differently-named attribute on...
Read more >Get a dictionary from an Objects Fields - GeeksforGeeks
There are two approaches to solve the above problem: By using the __dict__ attribute on an object of a class and attaining the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You could change the default resolver on the
Photo
Object type like this:Is it correct, that the
class Meta:
“feature” is only for Python 2?Is there any other workaround to set the
default_resolver
when using Python 3?