11from collections import OrderedDict
2+
23import six
34from sqlalchemy .inspection import inspect as sqlalchemyinspect
45from sqlalchemy .orm .exc import NoResultFound
56
6- from graphene import ObjectType , Field
7+ from graphene import Field , ObjectType
78from graphene .relay import is_node
9+ from graphene .types .objecttype import ObjectTypeMeta
10+ from graphene .types .options import Options
11+ from graphene .types .utils import merge , yank_fields_from_attrs
12+ from graphene .utils .is_base_type import is_base_type
13+
814from .converter import (convert_sqlalchemy_column ,
915 convert_sqlalchemy_composite ,
1016 convert_sqlalchemy_relationship )
11- from .utils import is_mapped
12-
13- from graphene .types .objecttype import ObjectTypeMeta
14- from graphene .types .options import Options
1517from .registry import Registry , get_global_registry
16- from graphene .utils .is_base_type import is_base_type
17- from graphene .types .utils import yank_fields_from_attrs , merge
18- from .utils import get_query
18+ from .utils import get_query , is_mapped
1919
2020
2121def construct_fields (options ):
@@ -96,7 +96,6 @@ def __new__(cls, name, bases, attrs):
9696 '{}.Meta, received "{}".'
9797 ).format (name , options .model )
9898
99-
10099 cls = ObjectTypeMeta .__new__ (cls , name , bases , dict (attrs , _meta = options ))
101100
102101 options .registry .register (cls )
@@ -116,6 +115,7 @@ def __new__(cls, name, bases, attrs):
116115
117116
118117class SQLAlchemyObjectType (six .with_metaclass (SQLAlchemyObjectTypeMeta , ObjectType )):
118+
119119 @classmethod
120120 def is_type_of (cls , root , context , info ):
121121 if isinstance (root , cls ):
@@ -124,7 +124,7 @@ def is_type_of(cls, root, context, info):
124124 raise Exception ((
125125 'Received incompatible instance "{}".'
126126 ).format (root ))
127- return type (root ) == cls ._meta .model
127+ return isinstance (root , cls ._meta .model )
128128
129129 @classmethod
130130 def get_query (cls , context ):
@@ -138,8 +138,8 @@ def get_node(cls, id, context, info):
138138 except NoResultFound :
139139 return None
140140
141- def resolve_id (root , args , context , info ):
141+ def resolve_id (self , args , context , info ):
142142 graphene_type = info .parent_type .graphene_type
143143 if is_node (graphene_type ):
144- return root .__mapper__ .primary_key_from_instance (root )[0 ]
145- return getattr (root , graphene_type ._meta .id , None )
144+ return self .__mapper__ .primary_key_from_instance (self )[0 ]
145+ return getattr (self , graphene_type ._meta .id , None )
0 commit comments