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

Add support for Non-Null SQLAlchemyConnectionField #261

Merged
merged 2 commits into from
Jun 4, 2020
Merged

Add support for Non-Null SQLAlchemyConnectionField #261

merged 2 commits into from
Jun 4, 2020

Conversation

chrisberks
Copy link
Contributor

SQLAlchemyConnectionField doesn't handle Non-Null wrapped types. Currently, passing required=True to SQLAlchemyConnectionField raises an exception.

@coveralls
Copy link

coveralls commented Feb 4, 2020

Coverage Status

Coverage increased (+0.03%) to 97.611% when pulling ba635c5 on chrisberks:nonnull-connection into 421f8e4 on graphql-python:master.

Copy link
Collaborator

@jnak jnak left a 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 Show resolved Hide resolved
graphene_sqlalchemy/fields.py Outdated Show resolved Hide resolved
return rewrap(of_type._meta.connection)

@property
def connection_type(self):
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

Copy link
Collaborator

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)

graphene_sqlalchemy/fields.py Outdated Show resolved Hide resolved
graphene_sqlalchemy/fields.py Outdated Show resolved Hide resolved
@chrisberks
Copy link
Contributor Author

@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):
Copy link
Collaborator

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

return rewrap(of_type._meta.connection)

@property
def connection_type(self):
Copy link
Collaborator

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)

Copy link
Collaborator

@jnak jnak left a 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.
Copy link
Collaborator

@jnak jnak left a 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

@jnak jnak merged commit 849217a into graphql-python:master Jun 4, 2020
@chrisberks
Copy link
Contributor Author

No problem at all, thanks for taking the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants