question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Defaulting the first param / paging by default

See original GitHub issue

I have the following snippet:

def resolve_products(self, info, **kwargs):
    return Product.objects.all()

I want to return 100 results by default. I notice that if I specify say first: 30 in my query

{ products (first: 30 ){} } that first appears in kwargs.

I then tried setting kwargs['first'] to 100 if no first key is found, but it has no effect.

How do I default first so all results do not get returned by default

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
gabelimoncommented, Oct 29, 2019

@muriloacs the easiest way that I’ve found to make this happen is to create a new connection field with an overridden connection_resolver. This is untested as I don’t need it right now but it should be about right.

from graphene_django.filter import DjangoFilterConnectionField


class AutoPagedDjangoFilterConnectionField(DjangoFilterConnectionField):
    @classmethod
    def connection_resolver(
        cls,
        resolver,
        connection,
        default_manager,
        max_limit,
        enforce_first_or_last,
        filterset_class,
        filtering_args,
        root,
        info,
        **args
    ):
        args['first'] = args.get("first", 40)
        return super().connection_resolver(
            cls,
            resolver,
            connection,
            default_manager,
            max_limit,
            enforce_first_or_last,
            filterset_class,
            filtering_args,
            root,
            info,
            **args
        )
3reactions
jkimbocommented, Oct 18, 2019

@gabelimon you can set a default value of a connection field like this:

from graphene import ObjectType, Int

class Query(ObjectType):
	users = DjangoFilterConnectionField(User, first=Int(default_value=100))
Read more comments on GitHub >

github_iconTop Results From Across the Web

Set default page size for JPA Pageable Object - Stack Overflow
If you are talking about a Spring Data PagingAndSortingRepository you can set the default page size by using the @PageableDefault on a Controller...
Read more >
Paging with Spring Boot - Reflectoring
With Spring Boot's configuration properties, we have fine-grained control over the defaults and parameter names. There are some potential ...
Read more >
Controlling pagination - Guidewire Documentation
The pageSize values for a resource defaults to defaultPageSize=25 and maxPageSize=100 . Individual resources may override these values in the API's apiconfig.
Read more >
Pagination - Django REST framework
Pagination is only performed automatically if you're using the generic views or viewsets. ... Defaults to the same value as the PAGE_SIZE settings...
Read more >
Pagination - Hot Chocolate - ChilliCream GraphQL Platform
If we want to enforce consistent pagination defaults throughout our app, we can do so by setting the global PagingOptions . C#. public...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found