Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Support Enums without explicit names #359

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def convert_column_to_float(type, column, registry=None):

@convert_sqlalchemy_type.register(types.Enum)
def convert_enum_to_enum(type, column, registry=None):
return lambda: enum_for_sa_enum(type, registry or get_global_registry())
return lambda: enum_for_sa_enum(type, registry or get_global_registry(), fallback_name=column.key)


# TODO Make ChoiceType conversion consistent with other enums
Expand Down
4 changes: 2 additions & 2 deletions graphene_sqlalchemy/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def _convert_sa_to_graphene_enum(sa_enum, fallback_name=None):
return Enum(name, members)


def enum_for_sa_enum(sa_enum, registry):
def enum_for_sa_enum(sa_enum, registry, fallback_name=None):
"""Return the Graphene Enum type for the specified SQLAlchemy Enum type."""
if not isinstance(sa_enum, SQLAlchemyEnumType):
raise TypeError(
"Expected sqlalchemy.types.Enum, but got: {!r}".format(sa_enum)
)
enum = registry.get_graphene_enum_for_sa_enum(sa_enum)
if not enum:
enum = _convert_sa_to_graphene_enum(sa_enum)
enum = _convert_sa_to_graphene_enum(sa_enum, fallback_name=fallback_name)
registry.register_enum(sa_enum, enum)
return enum

Expand Down