Added get_query into sqlalchemy objecttype

This commit is contained in:
Syrus Akbary 2016-09-09 19:04:21 -07:00
parent a8feba6ab4
commit 893d6f681e
2 changed files with 13 additions and 4 deletions

View File

@ -4,6 +4,12 @@ from .types import (
from .fields import ( from .fields import (
SQLAlchemyConnectionField SQLAlchemyConnectionField
) )
from .utils import (
get_query,
get_session
)
__all__ = ['SQLAlchemyObjectType', __all__ = ['SQLAlchemyObjectType',
'SQLAlchemyConnectionField'] 'SQLAlchemyConnectionField',
'get_query',
'get_session']

View File

@ -126,12 +126,15 @@ class SQLAlchemyObjectType(six.with_metaclass(SQLAlchemyObjectTypeMeta, ObjectTy
).format(root)) ).format(root))
return type(root) == cls._meta.model return type(root) == cls._meta.model
@classmethod
def get_query(cls, context):
model = cls._meta.model
return get_query(model, context)
@classmethod @classmethod
def get_node(cls, id, context, info): def get_node(cls, id, context, info):
try: try:
model = cls._meta.model return cls.get_query(context).get(id)
query = get_query(model, context)
return query.get(id)
except NoResultFound: except NoResultFound:
return None return None