Comments (5)
Thank you for the report 🙂
Can you please share something about the versions of graphene-sqlalchemy, sqlalchemy and graphene you're using and provide a reprodction including all involved ObjectTypes, Models, Enums and the Query? Without seeing the definition of AccommodationStatus it's hard to give any advice here.
from graphene-sqlalchemy.
Thank you for your fast reply! Sorry for the informations that I left out.
sqlalchemy: 1.4.46
graphene: 3.2.1
starlette-graphene3: 0.6.0
graphene-sqlalchemy: 3.0.0b3
Here is my enum:
class AccommodationStatus(str, Enum):
creating = 'creating'
active = 'active'
inactive = 'inactive'
Here is my schema:
class CombinedQuery(graphene.ObjectType):
accommodations = graphene.List(AccommodationGraphQL)
def resolve_accommodations(self, info):
query = AccommodationGraphQL.get_query(info)
return query.all()
schema = graphene.Schema(query=CombinedQuery)
And here is my query:
query {
accommodations {
id
status
}
}
If I modify my status field to a string in the ObjectType it will work and , but that takes away the advantages provided by enums
class AccommodationGraphQL(SQLAlchemyObjectType):
class Meta:
model = AccommodationModel
status = graphene.String()
OR if I write a custom resolver it will work again, but then I need to write resolvers to all my enums:
def resolve_status(self, info):
return self.status.value
from graphene-sqlalchemy.
Tried your code, but cannot reproduce the problem. Does it work for you with exactly this code? You can try putting it into a pytest testcase 🙂
class AccommodationStatus(str, PyEnum):
creating = 'creating'
active = 'active'
inactive = 'inactive'
class AccommodationModel(Base):
__tablename__ = "accommodations"
id = Column(Integer, primary_key=True)
status = Column(Enum(AccommodationStatus), nullable=False, default=AccommodationStatus.creating)
class AccommodationGraphQL(SQLAlchemyObjectType):
class Meta:
model = AccommodationModel
status = graphene.String()
class CombinedQuery(graphene.ObjectType):
accommodations = graphene.List(AccommodationGraphQL)
def resolve_accommodations(self, info):
return [AccommodationModel(id=1, status=AccommodationStatus.creating)]
schema = graphene.Schema(query=CombinedQuery)
query = """
query {
accommodations {
id
status
}
}
"""
result = schema.execute(query)
print(result)
print(json.dumps(result.formatted))
Enum 'AccommodationStatus' cannot represent value: <AccommodationStatus.active: 'creating'>
Judging by this error message, is there any chance this error was caused by you accidentally initializing the enum with status string active instead of creating when setting the enum value to active?
from graphene-sqlalchemy.
This issue was closed due to inactivity. If your request is still relevant, please open a new issue referencing this one and provide all of the requested information.
from graphene-sqlalchemy.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.
from graphene-sqlalchemy.
Related Issues (20)
- Flask example gives ImportError HOT 6
- How to remove "edges" and "node" from query? HOT 9
- examples/flask_sqlalchemy: dependency specification needed, due to breaking change in graphql-core ^3 HOT 1
- Expand docs with batching example
- Global ids from objects with composite primary keys are not correctly extracted (again) HOT 3
- Hybrid properties don't work in the presence of future annotations HOT 6
- Prioritize custom type conversion over standard conversions HOT 1
- Relationship isn't working if a model has a property named other than 'id'. HOT 5
- Support for sqlalchemy ^2.0.0 HOT 7
- flask_sqlalchemy example does not run with v3 release HOT 2
- hybrid_property annotations with built-in types defaulting to `ForwardRef` and failing schema compilation HOT 2
- Default sort HOT 1
- ORMField batching results in null result HOT 1
- filter: Guys, did you forgot on DateTimeFilter? HOT 1
- Requiring graphene_type for custom filters as well as type hints HOT 1
- Allow a custom filter class with the purpose of using all the base filters, and adding sqlalchemy-filter esk filters
- A way to add custom filters not specific to fields
- Conversion of BigInteger primary keys to ID
- MVC: support business logic layer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene-sqlalchemy.