strawberry-graphql / strawberry-django

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

feat: MPTT relations compatibility issue reproduction #551

Closed Eraldo closed 2 weeks ago

Eraldo commented 2 weeks ago

Description

Trying to get an author and then the total count of the children of that author breaks when there are no children present but requested in the query. Error:

"message": "An unknown error occurred."

The PR includes a test test_nexted_children.py, which illustrates the use case and resulting error.

FYI: Disabling the DjangoOptimizerExtension makes the test pass without any issue.

Types of Changes

Summary by Sourcery

This pull request enhances the RelayAuthor model by adding MPTT relations to support hierarchical data structures. Additionally, a new test case is introduced to verify the nested children count functionality.

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This pull request introduces an MPTT (Modified Preorder Tree Traversal) relation to the RelayAuthor model to address an issue where querying for an author and their children would break if no children were present. The changes include modifying the RelayAuthor model to inherit from MPTTModel, adding a parent field to establish the tree structure, and updating the AuthorType to include a children connection. A new test file, test_nested_children.py, is added to illustrate the issue and verify the fix.

File-Level Changes

Files Changes
tests/relay/lazy/models.py
tests/relay/lazy/a.py
Updated the RelayAuthor model to support MPTT relations and modified the AuthorType to include a children connection.
tests/relay/lazy/test_nested_children.py Added a new test file to verify the fix for querying authors and their children.

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.
bellini666 commented 2 weeks ago

Closing this as https://github.com/strawberry-graphql/strawberry-django/pull/553 superseded it