-
Notifications
You must be signed in to change notification settings - Fork 227
Make a Relay ConnectionField optimized to work with Query #89
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
Similar/same issue to graphql-python/graphene#589 |
Isn't this already covered here ? @classmethod
def connection_resolver(cls, resolver, connection, model, root, info, **args):
iterable = resolver(root, info, **args)
if iterable is None:
iterable = cls.get_query(model, info, **args)
if isinstance(iterable, Query):
_len = iterable.count()
else:
_len = len(iterable) |
Indeed it is. graphene-sqlalchemy/graphene_sqlalchemy/fields.py Lines 26 to 28 in 4827ce2
graphene.relay.Connection instead of a SQLAlchemyObjectType .Maybe I'm using it incorrectly? |
Yeah you need a SQLAlchemyObjectType there, everything gets down to an ObjectType eventually |
Following graphene 2.0 (https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md#node-connections), I defined explicit Connections. class User(SQLAlchemyObjectType):
class Meta:
model = UserModel
name = String()
class UserConnection(relay.Connection):
class Meta:
node = User
class Group(SQLAlchemyObjectType):
class Meta:
model = GroupModel
# Here, it works with the RelayConnectionField I posted in the issue.
# But breaks if I change to SQLAlchemyConnectionField
user_connection = RelayConnectionField(UserConnection)
class Query(ObjectType):
group = Field(Group) It does, however, work if I send the SQLAlchemyObjectType directly, like user_connection = SQLAlchemyConnectionField(User) But how can I add custom data to the Connection itself? |
You are mixing RelayConnectionFields with SqlAlchemy, You have to extend from SQLAlchemyConnectionField. I cant take a look right now, but check this as here we add fields to connections for counting purposes: |
@sebastiandev, thanks for the help.
|
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. |
Graphene has the
graphene.relay.ConnectionField
, which slices a list/iterable to build the edges inside the Relay connection.But it doesn't play well with DB queries. It calls
len()
withQuery
doesn't have.graphene-sqlalchemy should have a implementation of the ConnectionField that is aware of the sqlalchemy's Query and use it to slice directly in the DB.
For now, I'm using this workaround:
The text was updated successfully, but these errors were encountered: