strawberry-graphql / strawberry-django

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

test: Add some tests to ensure Interfaces can be properly optimized #554

Closed bellini666 closed 1 week ago

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This pull request addresses issue #550 by optimizing the handling of interfaces in the project. The changes include the addition of a new abstract model NamedModel to centralize the name field, updates to the GraphQL schema to use this new model, and the addition of a new test to ensure the correct functionality of the optimization.

File-Level Changes

Files Changes
tests/projects/models.py
tests/projects/schema.py
Refactored models to use a new abstract model NamedModel and updated the GraphQL schema to use a new interface Named.

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.80%. Comparing base (3481e8d) to head (da61de8).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #554 +/- ## ========================================== + Coverage 88.71% 88.80% +0.08% ========================================== Files 41 41 Lines 3527 3527 ========================================== + Hits 3129 3132 +3 + Misses 398 395 -3 ```

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

bellini666 commented 1 week ago

This failed to reproduce the issue that I wanted, but I think it is still a good variety for the test suite to have

stygmate commented 5 days ago

seems it don't work if class inherit from strawberry.relay.Node

@api_types.interface(models.Dossier)
class Dossier(strawberry.relay.Node):
    ...

produce AssertionError:

[...]
 File "/.../site-packages/strawberry_django/optimizer.py", line 859, in _get_model_hints_from_connection
    assert isinstance(n_gql_definition, GraphQLObjectType)
AssertionError