-
Notifications
You must be signed in to change notification settings - Fork 227
Support for hybrid_property? #15
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
Comments
Looking into this and the main issue I see atm is what type the value of hybrid_property will have? Columns and relationships the types can be determined by their definitions, but hybrid_property is dynamic. Graphene does have a dynamic property - looking into that. https://github.com/kvey/graphene-sqlalchemy/tree/feature/support-hybrid-property wip One way to solve the type issue is to rely on type annotations on the hybrid_property, but that'd depend on python3. Not sure what an actual solution is if anyone has any ideas. |
Thanks.. How I worked around the problem was that I had to explicitly declare the GraphQl type via the hybrid method name in the schema and then make sure the SQLAlchemy returned the exact type in the hybrid method. Works for now.. but it would be great if the SQLAlchemy could handle automatically. |
This is now fixed in |
My hybrid property always returns a list of SQLAlchemy objects, how can I let graphene-sqlalchemy know about this so it doesn't just return a string (so it can return the appropriate SQLAlchemyObjectType)? Also I am using python2 |
Can you please provide a sample. Might be easier. |
I want to tell graphene-sqlalchemy that the returned type for the hybrid_property is a list of SQLAlchemy objects |
@anisjonischkeit Just probably late answer to your Q (and help anyone who google this as i did), i had similar problem with hybrid property that returned boolean, but graphene-sqlalchemy was casting it to string ( class Subject(SQLAlchemyObjectType):
# is_managed is hybrid property so we need to force the type
is_managed = graphene.Boolean()
class Meta:
model = SubjectModel
interfaces = (relay.Node, ) After this i get correct Not sure if this fix can help with your problem or not, but i guess you should use something like |
@Salamek this should be mentioned in the official docs if using the hybrid property. Works like a charm! Here some example code for graphene-flask-sqlalchemy for beginners - just for documentation:
|
It'd be very nice if the hybrid_property translator could use something like the function's return type hints as the actual base for generating the final GraphQL type, so that we don't need to override the type in the final generated GraphQL object. |
@flipbit03 check out #333 |
I have opened a pull request for this in #340, satisfying most use cases with the types in the Standard Library and the List[T] container type. It also includes the ability to retrieve a previously generated SQLAlchemyObjectType. |
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. |
Hello,
I am trying to use hybrid_property as a property on a GraphQL response. However, when I execute the GraphQL request, I am receiving an error stating the property cannot be found.
Are SQlAlchemy hybrid_property attributes currently supported?
Thanks,
G
The text was updated successfully, but these errors were encountered: