strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
MIT License
391 stars 115 forks source link

fix: fix optimized nested connections failing to access totalCount #553

Closed bellini666 closed 2 weeks ago

bellini666 commented 2 weeks ago

When resolving the connection from cache, we were missing setting nodes in it 🤦‍♂️

We do have a test that was passing with this, but MPTT triggered the issue. The issue was probably happening to corner cases as well

Used https://github.com/strawberry-graphql/strawberry-django/pull/551 as a base for the reproduction, but adjusted it to avoid depending on python 3.9

Fix https://github.com/strawberry-graphql/strawberry-django/issues/552

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This pull request addresses an issue with nested MPTT (Modified Preorder Tree Traversal) connections when trying to access the totalCount in a GraphQL query. The changes include a fix in the resolve_connection method in strawberry_django/relay.py and the addition of several test files to ensure the correctness of the fix.

File-Level Changes

Files Changes
tests/relay/mptt/test_nested_children.py
tests/relay/mptt/test_lazy_annotations.py
Added tests to verify the correctness of nested MPTT connections and lazy type annotations in the schema.
tests/relay/mptt/a.py
tests/relay/mptt/b.py
tests/relay/mptt/models.py
Defined models and types for MPTTAuthor and MPTTBook with necessary connections and filters.

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - You can change your review settings at any time by accessing your [dashboard](https://sourcery.ai/dashboard): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.
codecov-commenter commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.71%. Comparing base (015621c) to head (98d9c9c).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #553 +/- ## ========================================== + Coverage 88.67% 88.71% +0.03% ========================================== Files 41 41 Lines 3524 3527 +3 ========================================== + Hits 3125 3129 +4 + Misses 399 398 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.