Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Default GraphQL Enums from Python Enums. #3543

Open
1 of 3 tasks
nrbnlulu opened this issue Jun 19, 2024 · 3 comments
Open
1 of 3 tasks

Feature: Default GraphQL Enums from Python Enums. #3543

nrbnlulu opened this issue Jun 19, 2024 · 3 comments

Comments

@nrbnlulu
Copy link
Member

nrbnlulu commented Jun 19, 2024

Feature Request Type

  • Core functionality
  • Alteration (enhancement/optimization) of existing feature(s)
  • 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
@erikwrede
Copy link
Member

I like this! We would need some sort of a registry to ensure we don't duplicate enums across types, but other than that it's a very straight-forward devX improvement.

The only "issue" I see is documentation - we need to make a decision on wether we want to include docstrings of the original python enum in the GraphQL schema, and we need to be aware that specific enum values are not annotatable with their own docstrings in python.

@patrick91
Copy link
Member

I like this! We would need some sort of a registry to ensure we don't duplicate enums across types, but other than that it's a very straight-forward devX improvement.

Good point! We might also think of this in the context of Strawberry Django (and other integrations)

Would we make a registry per schema, right? 😊

@erikwrede
Copy link
Member

Yes, per schema. We could directly use this for Django and Sqlalchemy to reduce redundancies there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants