-
Notifications
You must be signed in to change notification settings - Fork 229
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
Add support for Non-Null SQLAlchemyConnectionField #261
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this PR! This is going to allow us to make auto-generate connection fields required when possible.
graphene_sqlalchemy/fields.py
Outdated
return rewrap(of_type._meta.connection) | ||
|
||
@property | ||
def connection_type(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is confusing since type
already returns a connection. Also I'd rather not add another public property to this class since, as far as I can tell, it is only going to be used in model
and get_resolver
.
Can you instead call unwrap
/ get_nullable_type
directly in those functions? This is in-line with graphene.relay.ConnectionField
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to call get_nullable_type
in model
and get_resolver
as they expect non-wrapped types. Can you add something like this to your tests to make sure this is caught?
class Query(ObjectType):
pets = SQLAlchemyConnectionField(Pet.connection, required=True)
Schema(query=Query)
@jnak Thanks for the great feedback on this PR. I've listed the changes in the last commit message. Anything else let me know. |
@@ -17,6 +17,11 @@ class Meta: | |||
interfaces = (Node,) | |||
|
|||
|
|||
class PetConnection(Connection): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this. You can call Pet.connection
directly below
graphene_sqlalchemy/fields.py
Outdated
return rewrap(of_type._meta.connection) | ||
|
||
@property | ||
def connection_type(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to call get_nullable_type
in model
and get_resolver
as they expect non-wrapped types. Can you add something like this to your tests to make sure this is caught?
class Query(ObjectType):
pets = SQLAlchemyConnectionField(Pet.connection, required=True)
Schema(query=Query)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. Thanks for working on this.
Since SQLAlchemy 1.3.16 `orm.selectinload` will no longer `ORDER BY` the primary key of the parent entity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Sorry for dropping the ball on this. It's been tough to find time for this project lately.
Will be released soon on PyPi
No problem at all, thanks for taking the time. |
SQLAlchemyConnectionField
doesn't handle Non-Null wrapped types. Currently, passingrequired=True
toSQLAlchemyConnectionField
raises an exception.