mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Simplified instance field getter
This commit is contained in:
parent
b3dad1a120
commit
23ef63e60e
|
@ -55,12 +55,7 @@ class Field(object):
|
||||||
if resolve_fn:
|
if resolve_fn:
|
||||||
return resolve_fn(instance, args, info)
|
return resolve_fn(instance, args, info)
|
||||||
else:
|
else:
|
||||||
if isinstance(instance, BaseObjectType):
|
return getattr(instance, self.field_name, None)
|
||||||
return instance.get_field(self.field_name)
|
|
||||||
if hasattr(instance, self.field_name):
|
|
||||||
return getattr(instance, self.field_name)
|
|
||||||
elif hasattr(instance, self.name):
|
|
||||||
return getattr(instance, self.name)
|
|
||||||
|
|
||||||
@memoize
|
@memoize
|
||||||
def get_resolve_fn(self):
|
def get_resolve_fn(self):
|
||||||
|
|
|
@ -120,7 +120,7 @@ class BaseObjectType(object):
|
||||||
if not kwargs:
|
if not kwargs:
|
||||||
return None
|
return None
|
||||||
elif type(instance) is cls:
|
elif type(instance) is cls:
|
||||||
instance = instance.instance
|
return instance
|
||||||
|
|
||||||
return super(BaseObjectType, cls).__new__(cls)
|
return super(BaseObjectType, cls).__new__(cls)
|
||||||
|
|
||||||
|
@ -137,9 +137,6 @@ class BaseObjectType(object):
|
||||||
if self.instance:
|
if self.instance:
|
||||||
return getattr(self.instance, name)
|
return getattr(self.instance, name)
|
||||||
|
|
||||||
def get_field(self, field):
|
|
||||||
return getattr(self.instance, field, None)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resolve_objecttype(cls, schema, instance, *_):
|
def resolve_objecttype(cls, schema, instance, *_):
|
||||||
return instance
|
return instance
|
||||||
|
|
Loading…
Reference in New Issue
Block a user