Giter Site home page Giter Site logo

Comments (6)

bellini666 avatar bellini666 commented on August 16, 2024 1

Hi @yergom,

The current relay implementation is actually a mix of both. Although it is exposed as a cursor based pagination, it uses an offset strategy. The total number of results is currently exposed at the connection, so you can use that to know the number of pages.

Just like I mentioned in this issue, I'm trying to think of a good way to create a generic solution that could fit both approaches, and also allow the Edge/Connection to be easily expanded by the user. I'm not having much time to work on this right now, but hopefully I'll have next month.

from strawberry-django-plus.

theGleam avatar theGleam commented on August 16, 2024

Any luck with this, @bellini666?

I am happy to help. Would like to start from where you currently are with it.

from strawberry-django-plus.

bellini666 avatar bellini666 commented on August 16, 2024

Hey @theGleam ,

Don't know what actually needs to be implemented for this, since the current relay implementation uses offset based pagination by default. I also already made some changes to allow someone to easily override it to implement a custom cursor pagination as needed.

But if there's anything else missing still, feel free to open a PR and I'll gladly review it :)

from strawberry-django-plus.

tasiotas avatar tasiotas commented on August 16, 2024

hi @bellini666 ,

If current implementation already has offset support, how can I pass it to the query? I can only see cursor parameters, no offset.

image

purchases is implemented via custom method, it looks like @gql.django.connection doesnt accept pagination=True.
I did set pagination=True on ProductType.

    @gql.django.connection(directives=[IsOwner()])
    def purchases(self, info) -> List["ProductType"]:
        products = (
            Product.objects.filter(order__user__slug=self.slug)
            .annotate(order_number=F("order__order_number"), order_date=F("order__date"))
            .order_by("name")
        )
        return products
@gql.django.type(Product, filters=ProductFilter, pagination=True)
class ProductType(gql.relay.Node):
    name: gql.auto
    slug: gql.auto

    author: Annotated["UserType", gql.lazy("accounts.schema")]

Thank you

from strawberry-django-plus.

bellini666 avatar bellini666 commented on August 16, 2024

Hey @tasiotas ,

When using a resolver for the connection, you don't have control over the pagination itself. For that you will want to define your own Connection subclass define your custom implementation for from_nodes

Btw, I'm currently contributing the relay integration to strawberry in this PR. Its API has some improvements when compared to the one in this repo, which also includes a better approach for handling custom pagination implementations. And I'll integrate it with this once the PR is released.

from strawberry-django-plus.

tasiotas avatar tasiotas commented on August 16, 2024

gotcha! thank you

from strawberry-django-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.