Description
Im working with a connection Class of this shape:
class WishConnection(relay.Connection):
class Meta:
node = ProductType
class Edge:
through = graphene.Field(WishReasonType, description='Connection reason')
def resolve_through(self, info, **args):
return self.node.preason[0]
The problem is that I want to use django own queryset paginator to resolve the list that gets passed by the resolve for where the connection is used.
products = relay.ConnectionField(WishConnection)
def resolve_products(self, info, **args):
qs = Reason.objects.filter(wish=self).only('reason', 'qty')
len = args.get
result = Paginator(self.products.prefetch_related(
Prefetch('reason_set', queryset=qs, to_attr='preason')).all(),
args.get('first', 20))
return result
my query looks like
{
wish(pk: "2") {
products(first: 1, after: "YXJyYXljb25uZWN0aW9uOjA=", ) {
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
edges {
cursor
through {
reason
qty
}
node {
title
description
active
disabled
}
}
}
}
}
I would Like to mak my own PageInfo class that has the attributes that can be returned by djangos Paginator class like
Paginator.count
Paginator.num_pages
Paginator.page_range
and also the methods for each pages most notably has_next has_previous
https://docs.djangoproject.com/en/1.11/topics/pagination/#page-objects
In order to do that I need to be able to control how def connection_from_list_slice(...)
resolves for PageInfo and for that matter the nodes, which means that I will need to change this line to call my own method
graphene/graphene/relay/connection.py
Line 122 in c38ffa5
Simplest way to do that is to create a subclass of the ConnectionField and override the def resolve_connection
method.
well looks like I just found a path to a solution to my own problem. Going to post to see if anyone has anything to ask or add, also might comeback to this issue if I find any more problems or difficult behavior I don't know how to implement while trying to work this out.