From 5a08c5996c372bba6a4489405c5dfb6c5f6f6e54 Mon Sep 17 00:00:00 2001 From: rafalp Date: Thu, 10 Oct 2024 22:11:09 +0200 Subject: [PATCH] Add enum repr --- example/mutations/__init__.py | 2 ++ example/mutations/enum_repr.py | 19 +++++++++++++++++++ tests/test_mutation.py | 14 ++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 example/mutations/enum_repr.py diff --git a/example/mutations/__init__.py b/example/mutations/__init__.py index aead3b4..4e51381 100644 --- a/example/mutations/__init__.py +++ b/example/mutations/__init__.py @@ -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, ] diff --git a/example/mutations/enum_repr.py b/example/mutations/enum_repr.py new file mode 100644 index 0000000..70242d3 --- /dev/null +++ b/example/mutations/enum_repr.py @@ -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) diff --git a/tests/test_mutation.py b/tests/test_mutation.py index 32e2b8d..7dcfa2b 100644 --- a/tests/test_mutation.py +++ b/tests/test_mutation.py @@ -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": "", + }