strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
409 stars 118 forks source link

Fix: DjangoOptimizerExtension corrupts nested objects' fields' prefetch objects #380

Closed aprams closed 1 year ago

aprams commented 1 year ago

Description

This PR aims to resolve issue #379 .

I included a reproducible test and a suggested fix, where the Prefetch object gets deepcopied to avoid the side effects from add_prefix.

Considerations:

I'm also very open for improving the test case included. If you know a better way on how to do it without the custom type setup, please let me know.

Types of Changes

Issues Fixed or Closed by This PR

Checklist

I love the work you do here, thanks a lot for the really awesome work! ❤️

codecov-commenter commented 1 year ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (a17b51b) 87.98% compared to head (a6695b5) 87.99%. Report is 2 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #380 +/- ## ======================================= Coverage 87.98% 87.99% ======================================= Files 33 33 Lines 2971 2973 +2 ======================================= + Hits 2614 2616 +2 Misses 357 357 ``` | [Files](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/380?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql) | Coverage Δ | | |---|---|---| | [strawberry\_django/optimizer.py](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/380?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql#diff-c3RyYXdiZXJyeV9kamFuZ28vb3B0aW1pemVyLnB5) | `89.13% <100.00%> (+0.06%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/strawberry-graphql/strawberry-graphql-django/pull/380/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql)

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