Skip to content

Commit

Permalink
Commit missing package
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Oct 5, 2024
1 parent 35d4f1a commit 752d2b8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions example/queries/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from . import groups, hello, users

queries = [
groups.Query,
hello.Query,
users.Query,
]
31 changes: 31 additions & 0 deletions example/queries/groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ariadne_graphql_modules import GraphQLObject
from graphql import GraphQLResolveInfo

from ..database import db
from ..enums.groupfilter import GroupFilter
from ..types.group import GroupType


class Query(GraphQLObject):
@GraphQLObject.field(args={"filter_": GraphQLObject.argument("filter")})
@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)
except (TypeError, ValueError):
return None

return await db.get_row("groups", id=id_int)
11 changes: 11 additions & 0 deletions example/queries/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ariadne_graphql_modules import GraphQLObject
from graphql import GraphQLResolveInfo


class Query(GraphQLObject):
hello: str

@GraphQLObject.resolver("hello")
@staticmethod
def resolve_hello(obj, info: GraphQLResolveInfo) -> str:
return "Hello world!"
12 changes: 12 additions & 0 deletions example/queries/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from ariadne_graphql_modules import GraphQLObject
from graphql import GraphQLResolveInfo

from ..database import db
from ..types.user import UserType


class Query(GraphQLObject):
@GraphQLObject.field()
@staticmethod
async def users(obj, info: GraphQLResolveInfo) -> list[UserType]:
return await db.get_all("users")

0 comments on commit 752d2b8

Please sign in to comment.