Closed
Description
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()
with Query
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:
class RelayConnectionField(graphene.relay.ConnectionField):
@classmethod
def resolve_connection(cls, connection_type, args, resolved):
if isinstance(resolved, Query):
len_ = resolved.count()
connection = connection_from_list_slice(
resolved,
args,
connection_type=connection_type,
edge_type=connection_type.Edge,
pageinfo_type=PageInfo,
slice_start=0,
list_length=len_,
list_slice_length=len_,
)
connection.iterable = resolved
return connection
else:
return super().resolve_connection(connection_type, args, resolved)
Metadata
Metadata
Assignees
Labels
No labels