diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..64f880a --- /dev/null +++ b/.pylintrc @@ -0,0 +1,2 @@ +[MESSAGES CONTROL] +disable=C0114, C0115, C0116, W0613 diff --git a/example/schema.py b/example/schema.py index 3161ea9..0d28cb4 100644 --- a/example/schema.py +++ b/example/schema.py @@ -16,16 +16,20 @@ def resolve_hello(obj, info: GraphQLResolveInfo) -> str: return "Hello world!" @GraphQLObject.field(args={"filter_": GraphQLObject.argument("filter")}) - async def groups(obj, info: GraphQLResolveInfo, filter_: GroupFilter) -> list[GroupType]: + @staticmethod + async def groups( + obj, info: GraphQLResolveInfo, filter_: GroupFilter = GroupFilter.ALL + ) -> list[GroupType]: if filter_ == GroupFilter.ADMIN: return await db.get_all("groups", is_admin=True) if filter_ == GroupFilter.MEMBER: return await db.get_all("groups", is_admin=False) - + return await db.get_all("groups") @GraphQLObject.field() + @staticmethod async def group(obj, info: GraphQLResolveInfo, id: str) -> GroupType | None: try: id_int = int(id) @@ -35,6 +39,7 @@ async def group(obj, info: GraphQLResolveInfo, id: str) -> GroupType | None: return await db.get_row("groups", id=id_int) @GraphQLObject.field() + @staticmethod async def users(obj, info: GraphQLResolveInfo) -> list[UserType]: return await db.get_all("users") diff --git a/tests/test_query.py b/tests/test_query.py index 7632ad6..ad5befa 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -5,3 +5,63 @@ async def test_query_hello_field(exec_query): result = await exec_query("{ hello }") assert result.data == {"hello": "Hello world!"} + + +@pytest.mark.asyncio +async def test_query_groups_field(exec_query): + result = await exec_query("{ groups(filter: ALL) { id name } }") + assert result.data == { + "groups": [ + { + "id": "1", + "name": "Admins", + }, + { + "id": "2", + "name": "Members", + }, + ], + } + + +@pytest.mark.asyncio +async def test_query_groups_field_all_arg(exec_query): + result = await exec_query("{ groups(filter: ALL) { id name } }") + assert result.data == { + "groups": [ + { + "id": "1", + "name": "Admins", + }, + { + "id": "2", + "name": "Members", + }, + ], + } + + +@pytest.mark.asyncio +async def test_query_groups_field_admin_arg(exec_query): + result = await exec_query("{ groups(filter: ADMIN) { id name } }") + assert result.data == { + "groups": [ + { + "id": "1", + "name": "Admins", + }, + ], + } + + +@pytest.mark.asyncio +async def test_query_groups_field_member_arg(exec_query): + result = await exec_query("{ groups(filter: MEMBER) { id name } }") + assert result.data == { + "groups": [ + { + "id": "2", + "name": "Members", + }, + ], + }