strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations πŸ“
https://strawberry.rocks
MIT License
4.02k stars 533 forks source link

Add support for using raw Python enum types in schema #3639

Closed nrbnlulu closed 1 month ago

nrbnlulu commented 1 month ago

Description

Types of Changes

Issues Fixed or Closed by This PR

fix #3543

Checklist

Summary by Sourcery

Add support for using raw Python enum types in schemas, enabling the use of enums without @strawberry.enum decoration. Fix issue #3543 and update tests to cover the new functionality. Document the changes in RELEASE.md.

New Features:

Bug Fixes:

Documentation:

Tests:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request adds support for using raw Python enum types in Strawberry schemas without requiring the @strawberry.enum decorator. The changes primarily affect the enum handling in the Strawberry library, allowing for more flexible use of enum types from external sources.

File-Level Changes

Change Details Files
Added support for raw Python enum types in schemas
  • Removed the test case that raised an error for non-decorated enums
  • Added new test cases for default enum, StrEnum, and IntEnum implementations
  • Modified the create_enum method to use strawberry_enum for non-decorated enums instead of raising an error
tests/enums/test_enum.py
strawberry/annotation.py
Added release notes for the new feature
  • Created a new RELEASE.md file
  • Described the new functionality and provided an example use case
RELEASE.md

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - 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.
botberry commented 1 month ago

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release adds support for using raw Python enum types in your schema (enums that are not decorated with @strawberry.enum)

This is useful if you have enum types from other places in your code that you want to use in strawberry. i.e

# somewhere.py
from enum import Enum

class AnimalKind(Enum):
    AXOLOTL, CAPYBARA = range(2)

# gql/animals
from somewhere import AnimalKind

@strawberry.type
class AnimalType:
    kind: AnimalKind

Here's the tweet text:

πŸ†• Release (next) is out! Thanks to Χ Χ™Χ¨ for the PR πŸ‘

Get it here πŸ‘‰ https://strawberry.rocks/release/(next)
codecov[bot] commented 1 month ago

Codecov Report

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

Project coverage is 96.94%. Comparing base (596461b) to head (d0a0a84). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #3639 +/- ## ========================================== + Coverage 96.66% 96.94% +0.27% ========================================== Files 504 503 -1 Lines 33448 33457 +9 Branches 5600 5602 +2 ========================================== + Hits 32333 32434 +101 + Misses 881 791 -90 + Partials 234 232 -2 ```
codspeed-hq[bot] commented 1 month ago

CodSpeed Performance Report

Merging #3639 will not alter performance

Comparing nrbnlulu:default-enums (d0a0a84) with main (596461b)

Summary

βœ… 15 untouched benchmarks

patrick91 commented 1 month ago

@erikwrede you mean the failing test, right?

erikwrede commented 1 month ago

@patrick91 i just meant the wrong file @nrbnlulu mentioned but looks good now 😊