Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Oct 4, 2024
1 parent eabaf40 commit 7b257b0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=C0114, C0115, C0116, W0613
9 changes: 7 additions & 2 deletions example/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

Expand Down
60 changes: 60 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
}

0 comments on commit 7b257b0

Please sign in to comment.