Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change relay connection limit in graphene django

In graphene-django I have a pagination limit set in my settings.py file like below.

GRAPHENE = {
    'RELAY_CONNECTION_MAX_LIMIT': 150,
}

Let's say a particular query returns 200 items (I don't know beforehand) and I want to display all of this data on a graph. How do I stop graphene from paginating it when returning the results?

like image 295
chidimo Avatar asked Sep 06 '25 03:09

chidimo


1 Answers

You can override the max_limit argument for every DjangoFilterConnectionField individually. Setting this to None basically disables the limiting behaviour.

Suppose you have the following query for a UserNode class:

class UserQuery(graphene.ObjectType):
    all_users = DjangoFilterConnectionField(UserNode, max_limit=None)

The max_limit parameter will internally be processed by the DjangoConnectionClass which provides the limiting behaviour via the mentioned setting RELAY_CONNECTION_MAX_LIMIT

Beware though that this might lead to drastic performance issues in case of very large or expensive queries. Personally I would probably go for either a very high but still resonable limit depending on your data or preferrably look into implementing proper pagination behaviour on the client side.

like image 180
Ole Avatar answered Sep 07 '25 19:09

Ole