graphene
graphene copied to clipboard
How to get access to the queried object instance to get its attributes
Hi, Having this graphql schema:
class GQUser(graphene.ObjectType):
id = graphene.Int()
def resolve_id(self, args, info):
return None #... ? Return what ?
class GQQuery(graphene.ObjectType):
user = graphene.List(GQUser)
def resolve_user(self, args, info):
return [User(id = 3, username = "paul"), User(id = 4, username = "peter")]
and this query:
query Users {
user {
id
}
}
How can I gain access to the particular User instance (corresponding item of the list returned by resolve_user) to get its id attribute in GQUser.resolve_id method?
If you remove the resolve_id method in the GQUser class it will automatically took it.
However if you still want to get it you can do return self.id