mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 20:27:03 +03:00
21 lines
607 B
Python
21 lines
607 B
Python
from sqlalchemy.ext.declarative.api import DeclarativeMeta
|
|
|
|
|
|
def get_session(context):
|
|
return context.get('session')
|
|
|
|
|
|
def get_query(model, context):
|
|
query = getattr(model, 'query', None)
|
|
if not query:
|
|
session = get_session(context)
|
|
if not session:
|
|
raise Exception('A query in the model Base or a session in the schema is required for querying.\n'
|
|
'Read more http://graphene-python.org/docs/sqlalchemy/tips/#querying')
|
|
query = session.query(model)
|
|
return query
|
|
|
|
|
|
def is_mapped(obj):
|
|
return isinstance(obj, DeclarativeMeta)
|