How can I reference an enum type created by SqlAlchemy mapping ?
See original GitHub issueHi:
I would like to reuse an Enum type I’ve mapped in one class. Lets say I had the class Patient:
class Patient(Base):
__tablename__ = 'patients'
id = Column(CHAR(32), default=generate_uuid, nullable=False, primary_key=True)
name = Column(Text)
sex = Column(Enum('MALE', 'FEMALE', name='Sex'), nullable=False)
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType
from app.models.patient import Patient as PatientModel
class Patient(SQLAlchemyObjectType):
class Meta:
model = PatientModel
interfaces = (relay.Node,)
That is perfectly mapped to a Sex graphql type. But if I would like to create a new Patient, How can I reference the Sex enum type generated by graphene-sqlalchemy e.g in an input type ?
class CreatePatient(relay.ClientIDMutation):
class Input:
name = graphene.String()
sex = ???
BTW I’m using latest master branch version.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Best way to do enum in Sqlalchemy? - Stack Overflow
First, import the Python enum, the SQLAlchemy Enum, and your SQLAlchemy declarative base wherever you're going to declare your custom SQLAlchemy ...
Read more >The Type Hierarchy - SQLAlchemy 1.4 Documentation
The Enum type will make use of the backend's native “ENUM” type if one is available; otherwise, it uses a VARCHAR datatype. An...
Read more >database - Enum or reference table when dealing with maps
I am using sqlalchemy for my database ORM, which includes an enum type that makes it really easy to use an enum column....
Read more >Enum HOWTO — Python 3.11.1 documentation
The most interesting thing about enum members is that they are singletons. EnumType creates them all while it is creating the enum class...
Read more >Using Python enums in SQLAlchemy models
Create a custom field type ; """ Enables passing in a Python enum and storing the enum's *value* in the db. The default...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi there! Do we have a better way to achieve this, now? apart from doing
if...else if.Since #78 and #98 are merged, I expect this problem to be fixed. @annshress, I don’t know what you are referring to with
if...else if. If your problem persists, please open a new issue, including an example of your Models. 🙂