diff --git a/graphene-sqlalchemy/graphene_sqlalchemy/types.py b/graphene-sqlalchemy/graphene_sqlalchemy/types.py index e0bd9292..c4e4c8cd 100644 --- a/graphene-sqlalchemy/graphene_sqlalchemy/types.py +++ b/graphene-sqlalchemy/graphene_sqlalchemy/types.py @@ -3,7 +3,7 @@ import six from sqlalchemy.inspection import inspect as sqlalchemyinspect from sqlalchemy.orm.exc import NoResultFound -from graphene import ObjectType +from graphene import ObjectType, Field from graphene.relay import is_node from .converter import (convert_sqlalchemy_column, convert_sqlalchemy_relationship) @@ -13,7 +13,7 @@ from graphene.types.objecttype import ObjectTypeMeta from graphene.types.options import Options from .registry import Registry, get_global_registry 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 @@ -89,9 +89,9 @@ class SQLAlchemyObjectTypeMeta(ObjectTypeMeta): options.registry.register(cls) - options.sqlalchemy_fields = get_fields_in_type( - ObjectType, - construct_fields(options) + options.sqlalchemy_fields = yank_fields_from_attrs( + construct_fields(options), + _as=Field, ) options.fields = merge( options.interface_fields, diff --git a/graphene/types/utils.py b/graphene/types/utils.py index 7f7a19f5..c171e9e0 100644 --- a/graphene/types/utils.py +++ b/graphene/types/utils.py @@ -65,7 +65,7 @@ def get_field_as(value, _as=None): 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) and return them ordered @@ -76,6 +76,9 @@ def yank_fields_from_attrs(attrs, _as=None): if not field: continue 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)