-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding totalCount
in non-relay pagination: suggestion regarding approaches
#408
Comments
totalCount
in non-relay nodes: suggestion regarding approachestotalCount
in non-relay pagination: suggestion regarding approaches
Hi @stoicsleuth , Customizing the For curiosity, why is it breaking for you? If you want to show some examples, either here or at discord, I can try to help you find a way to workaround that |
Hey @bellini666, thanks for checking this out. What was breakingThe thing that was breaking for us was Step 1Initially we were using the
This was working as expected - and Strawberry Django could correctly identity the Step 2After that, we customized the These are the changes we did -
This will ensure that the query results are in the form of
Step 3In light of these changes, we then modified the return type in the query definition as well, as follows.
And this is where things broke, because Strawberry Django was unable to find the model type of the query from SolutionFor now, we solved this issue by customizing the |
Ohhh I see. Yeah, I think that is the way to go right now. We do have a similar workaround for connections in https://github.com/strawberry-graphql/strawberry-graphql-django/blob/main/strawberry_django/fields/base.py#L74 Wondering if it would make sense to change that code to check for a generic type and retrieve the django_type from its specialized type instead of doing that only for Maybe the |
Hey @stoicsleuth, we are currently facing the same problem where we need to have the totalCount without using relay. Would you mind sharing more about the solution you are using? with more details on how the the |
Folks, I've put a significant sponsorship on this issue because it's beginning to kill me a bit. I think it'll take me two days to figure out so there's a 'two days of effort' bounty on there (better to share the money than take the pain!). For me to release that, I think the reasonable criteria are:
I hope that sounds sensible. |
@thclark nice, thank you for the sponsorship! I'll tackle that during the weekend :). And yes, your criteria sound totally reasonable |
my hero! |
@thclark I'm leaning toward the idea of making relay connections more generic. I just opened a PR on strawberry for that: strawberry-graphql/strawberry#3669 Let me just wait to get some feedback from the other devs (specially @patrick91 ) to make sure this is something that we really want, and then my idea is to leverage that new generic What do you think? Do you see any issues with this direction? UPDATE: Actually, after thinking more about this, even though it makes sense to make the relay's Having said that, I started that in this PR: #642 Can you please take a look and give me your feedback on whether this is what you are expecting from this functionality? The initial tests I wrote should give you a good idea on how it would work. If the idea is good, I'll complete it by adding tests to ensure that it plays well with the optimizer, permissions, etc and also update the documentation to explain how to use it. |
@thclark finished the documentation, the PR is done for review |
Thank you @bellini666 for contributing to close this issue! ⭐ The rewards from this issue, totaling $700, has been shared with you. What now?
If you already have a Polar account setup, you don't need to do anything. |
@thclark sorry for the delay in getting this merged. I just relocated to a new country (from Brazil to the Netherlands) and it consumed most of my free time during the last 2 weeks (well, it is still consuming 😅) Let me know if you find any issues with that and I'll try to solve any issues ASAP |
Summary
We're using Strawberry Graphql Django in our app and we would need a
totalCount
attribute for our queries in order show it in the frontend. I had previously raised blb-ventures/strawberry-django-plus#190 in which it was suggested to use a relay node for this purpose.However, considering our entire application now is built on top of non-relay nodes, we don't necessarily want to change everything to relay nodes at this point. However, we have figured out two approaches to include our custom pagination logic by overriding the
StrawberryDjangoField
class. Before committing to an approach, we wanted to get some feedback from the team as to which one seems to be more aligned with the library.Problem Statement
We have create a
PaginatedConnection
class which we are using as a type for our query nodes to include the count metadata as follows.However, this breaks the strawberry django internal functions as it can't identify the
django_type
(and consequentlydjango_model
) properly anymore.Proposed Solutions
django_type field
inCustomStrawberryField
-> Here we are overriding the property to modify the origin to be theRecordNode
instead ofPaginationConnection
. (We saw that this approach is being followed to resolved the relay node type internally indjango_type
)CustomStrawberryField
and then setting the internaldjango_model
in the__init__
function. This will directly set thedjango_model
no matter what the result of `django_type is.As we aren't sure about any proposed future changes to the library's internal API, we wanted to be double sure we are making the correct decision in terms of customizing the
StrawberryDjangoField
. Please let us know what you folks think about it.Upvote & Fund
The text was updated successfully, but these errors were encountered: