Skip to content

Commit

Permalink
Add enum repr
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Oct 10, 2024
1 parent 63ebf21 commit 5a08c59
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/mutations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
calc,
compare_roles,
dates_delta,
enum_repr,
)

mutations: list[Any] = [
calc.Mutation,
compare_roles.Mutation,
dates_delta.Mutation,
enum_repr.Mutation,
]
19 changes: 19 additions & 0 deletions example/mutations/enum_repr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from enum import IntEnum

from ariadne_graphql_modules import GraphQLObject
from graphql import GraphQLResolveInfo

from ..enums.role import RoleEnum


class TestEnum(IntEnum):
LOREM = 0
IPSUM = 1
DOLOR = 2


class Mutation(GraphQLObject):
@GraphQLObject.field(name="enumRepr")
@staticmethod
def resolve_enum_repr(obj, info: GraphQLResolveInfo, *, val: TestEnum) -> str:
return repr(val)
14 changes: 14 additions & 0 deletions tests/test_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ async def test_query_dates_delta_mutation(exec_query):
"days": 3751,
},
}


@pytest.mark.asyncio
async def test_query_enum_repr_mutation(exec_query):
result = await exec_query(
"""
mutation EnumRepr {
enumRepr(val: LOREM)
}
"""
)
assert result.data == {
"enumRepr": "<TestEnum.LOREM: 0>",
}

0 comments on commit 5a08c59

Please sign in to comment.