mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-17 03:50:44 +03:00
Fixed SQLAlchemy integration
This commit is contained in:
parent
4a2f10b116
commit
dac4f2dc19
|
@ -3,7 +3,7 @@ import six
|
||||||
from sqlalchemy.inspection import inspect as sqlalchemyinspect
|
from sqlalchemy.inspection import inspect as sqlalchemyinspect
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
from graphene import ObjectType
|
from graphene import ObjectType, Field
|
||||||
from graphene.relay import is_node
|
from graphene.relay import is_node
|
||||||
from .converter import (convert_sqlalchemy_column,
|
from .converter import (convert_sqlalchemy_column,
|
||||||
convert_sqlalchemy_relationship)
|
convert_sqlalchemy_relationship)
|
||||||
|
@ -13,7 +13,7 @@ from graphene.types.objecttype import ObjectTypeMeta
|
||||||
from graphene.types.options import Options
|
from graphene.types.options import Options
|
||||||
from .registry import Registry, get_global_registry
|
from .registry import Registry, get_global_registry
|
||||||
from graphene.utils.is_base_type import is_base_type
|
from graphene.utils.is_base_type import is_base_type
|
||||||
from graphene.types.utils import get_fields_in_type, merge
|
from graphene.types.utils import yank_fields_from_attrs, merge
|
||||||
from .utils import get_query
|
from .utils import get_query
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,9 +89,9 @@ class SQLAlchemyObjectTypeMeta(ObjectTypeMeta):
|
||||||
|
|
||||||
options.registry.register(cls)
|
options.registry.register(cls)
|
||||||
|
|
||||||
options.sqlalchemy_fields = get_fields_in_type(
|
options.sqlalchemy_fields = yank_fields_from_attrs(
|
||||||
ObjectType,
|
construct_fields(options),
|
||||||
construct_fields(options)
|
_as=Field,
|
||||||
)
|
)
|
||||||
options.fields = merge(
|
options.fields = merge(
|
||||||
options.interface_fields,
|
options.interface_fields,
|
||||||
|
|
|
@ -65,7 +65,7 @@ def get_field_as(value, _as=None):
|
||||||
return mount_as(value, _as)
|
return mount_as(value, _as)
|
||||||
|
|
||||||
|
|
||||||
def yank_fields_from_attrs(attrs, _as=None):
|
def yank_fields_from_attrs(attrs, _as=None, delete=True, sort=True):
|
||||||
'''
|
'''
|
||||||
Extract all the fields in given attributes (dict)
|
Extract all the fields in given attributes (dict)
|
||||||
and return them ordered
|
and return them ordered
|
||||||
|
@ -76,6 +76,9 @@ def yank_fields_from_attrs(attrs, _as=None):
|
||||||
if not field:
|
if not field:
|
||||||
continue
|
continue
|
||||||
fields_with_names.append((attname, field))
|
fields_with_names.append((attname, field))
|
||||||
del attrs[attname]
|
if delete:
|
||||||
|
del attrs[attname]
|
||||||
|
|
||||||
return OrderedDict(sorted(fields_with_names, key=lambda f: f[1]))
|
if sort:
|
||||||
|
fields_with_names = sorted(fields_with_names, key=lambda f: f[1])
|
||||||
|
return OrderedDict(fields_with_names)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user