I was a bit surprised that the following code snippet prints {'userType': 'BLAH'}
instead of {'userType': 'c'}
from enum import Enum
import graphql
import strawberry
@strawberry.type
class User:
@strawberry.enum
class UserType(Enum):
A = "a"
B = "b"
BLAH = "c"
name: str
user_type: UserType
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return User(
name="Bob",
user_type=User.UserType.BLAH
)
schema = strawberry.Schema(query=Query)
query = "{ user { userType } }"
result = graphql.graphql_sync(schema, query)
user = result.data['user']
print(user)
Is there a way to have the response use the Enum's value instead of its name? If the name is supposed to be used, is there any reason to define values instead of using Enum.auto()
?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too