strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Feature: Default GraphQL Enums from Python Enums.

Open nrbnlulu opened this issue 1 month ago • 3 comments

Feature Request Type

  • [ ] Core functionality
  • [ ] Alteration (enhancement/optimization) of existing feature(s)
  • [x] New behavior

Description

Currently to register a GraphQL Enum from an existing enums that resides elsewhere in your code base you need to do the following ~

from somewhere import MyEnum

MyEnumGQL = strawberry.enum(MyEnum)

@strawberry.type
class Foo:
	bar: MyEnumGQL

This results in a pyright error that can be fixed like this

from somewhere import MyEnum
if TYPE_CHECKING:
	MyEnumGQL = MyEnum
else:
	MyEnumGQL = strawberry.enum(MyEnum)
	
@strawberry.type
class Foo:
	bar: MyEnumGQL

It would be nice if we could just use a default GraphQL implementation of the enum on the fly so that the strawberry.enum call would not be needed.

from somewhere import MyEnum

@strawberry.type
class Foo:
	bar: MyEnum

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

nrbnlulu avatar Jun 19 '24 16:06 nrbnlulu