-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Optional Pagination #168
Optional Pagination #168
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fruitymedley - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@bellini666 Hi! Wanted to flag this to you for review since you look like the most recent active contributor, or if you know who would be best, I would greatly appreciate it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution in general looks good. I would just change it to be an argument instead, so it is more aligned to how we do those kind of configurations on strawberry.
Maybe @patrick91 and/or @erikwrede can also take a look at this?
@@ -146,6 +146,20 @@ async def resolve_async(nodes=nodes): | |||
return resolve_nodes(session) | |||
|
|||
|
|||
def exclude_relay( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this would be better defined in mapper.type
as an argument?
Also, the name itself IMO implies you are excluding relay functionality, which is not totally true. My suggestion would be do the argument and call it map_relations_as_list: bool = True
, in which you can opt-out as False
(would be even better to be the other way around, but then it would be a breaking change)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see a situation in which a type might have both relay and list. Would it make sense to add a class property in the same vein as __exclude__
?
CodSpeed Performance ReportMerging #168 will not alter performanceComparing Summary
|
I've made a few updates in accordance with the suggestions. Please review as available. |
@fruitymedley would this work for you as a global configuration, instead of a configuration on the type itself? |
@fruitymedley Now that the project has a maintainer again in @Ckk3, perhaps we can get this merged. @Ckk3 What do you think about the global vs typed-based configuration? |
Sorry, I'm a bit late to the party... I agree with Patrick about having a global config on how to handle Another, perhaps more opinionated approach, would be to work with the global config and use an explicit field definition, like Another option would be to have a custom strawberry.sqlfield, similar to graphene-sqlalchemy's ORMField which gives an option to input the uselist param. Generally, I think we should discuss a bit further on this and I'm open to all ideas. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, @fruitymedley , for your contribution! 🙌 This PR is looking great, and I just have a minor change related to the tests. I haven’t made any changes to the PR itself, but I wanted to note that if think we’ll need to update the documentation later to reflect the new functionality.
I'll also send a separate message soon with my thoughts on the global vs. type-based configuration discussion.
Looking forward to your feedback on the test updates!
tests/test_mapper.py
Outdated
assert len(mapped_department_type.__strawberry_definition__._fields) == 3 | ||
department_type_fields = mapped_department_type.__strawberry_definition__._fields | ||
name = next(iter(filter(lambda f: f.name == "employees", department_type_fields))) | ||
assert type(name.type) != StrawberryOptional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fruitymedley, I believe the comparison should be done using isinstance(name.type, StrawberryOptional)
instead of using !=
. This aligns with the conventions we're following in the codebase when checking if a type is StrawberryOptional
.
I came across a couple of instances in the code that confirm this pattern:
Here, we're using isinstance
to check for StrawberryOptional
in the type_.of_type
.
Similarly, here, the same pattern is used for type_
.
What do you think?
Hi everyone! I don’t have a strong preference, but after reviewing the code and looking at the implementation in Strawberry Django, I think the current approach in this PR solves the issue. However, I believe a global configuration might be a better solution. Please correct me if I’m wrong, @bellini666 , as I know you’re more familiar with the Django integration. In Strawberry Django’s documentation, I noticed that pagination can be configured both at the type level and on individual fields.
If I understand correctly, this PR introduces the second approach (configuring pagination on individual fields within a type), but I agree with @erikwrede's point:
I also align with @bellini666 later comment. In my opinion, we should apply this configuration at the type level, similar to What do you all think? Please let me know if I misunderstood anything, I'm still getting familiar with the Django integration. |
Hi, @fruitymedley , we have fixed the CI, can you please update your branch from main? |
@Ckk3 @erikwrede so, the way Strawberry Django currently does is to enforce a declarative style, in which you can use For example: @strawberry_django.type(Fruit):
class FruitType:
...
@strawberry_django.type(Color):
class ColorType:
# Does not auto resolve to the type, as we don't keep a mapping internally.
# Instead, one-to-one/many-to-one relations are mapped to `DjangoModelType` and
# one-to-many/many-to-many are mapped to `list[DjangoModelType]`
# `DjangoModelType` is a simple type that contains `pk` in it:
# https://github.com/strawberry-graphql/strawberry-django/blob/main/strawberry_django/fields/types.py#L75
fruits: auto
# The recommended way for lists. The integration will still know that we have a
# relation in the model and do what needs to be done regarding optimization
fruits: list[Fruit]
# The same as list above, but use relay connections instead.
fruits: relay.ListConnection[Fruit] I know that strawberry-sqlalchemy currently doesn't support the declarative style very well. Hence, a solution like the one proposed here is probably the way to go for now. Still, I'd love to see this integration moving forward to now only allow, but maybe actually enforce that in the future, so it is more aligned to strawberry style and recommendations in general. |
I agree with @bellini666 , lets continue with this PR when you can @fruitymedley |
Hi @fruitymedley, This PR has been inactive for two weeks. Are you still able to work on it? If not, please let me know so we can continue the development from this point. |
I will continue the development of this PR. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #168 +/- ##
==========================================
+ Coverage 85.38% 85.51% +0.12%
==========================================
Files 16 16
Lines 1615 1629 +14
Branches 128 139 +11
==========================================
+ Hits 1379 1393 +14
+ Misses 183 173 -10
- Partials 53 63 +10 |
I've fixed this PR tests and update the code with the new strawberry version. |
I'll merge this PR. |
Thanks for contributing to Strawberry! 🎉 You've been invited to join You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67 And don't forget to join our discord server: https://strawberry.rocks/discord 🔥 |
Implements optional pagination as requested in #167
Description
Types of Changes
Issues Fixed or Closed by This PR
#167
Checklist