-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,6 @@ | ||
from ariadne_graphql_modules import GraphQLObject, make_executable_schema | ||
from graphql import GraphQLResolveInfo | ||
from ariadne_graphql_modules import make_executable_schema | ||
|
||
from .database import db | ||
from .enums.groupfilter import GroupFilter | ||
from .types.group import GroupType | ||
from .types.user import UserType | ||
from .queries import queries | ||
|
||
|
||
class Query(GraphQLObject): | ||
hello: str | ||
|
||
@GraphQLObject.resolver("hello") | ||
@staticmethod | ||
def resolve_hello(obj, info: GraphQLResolveInfo) -> str: | ||
return "Hello world!" | ||
|
||
@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) | ||
|
||
@GraphQLObject.field() | ||
@staticmethod | ||
async def users(obj, info: GraphQLResolveInfo) -> list[UserType]: | ||
return await db.get_all("users") | ||
|
||
|
||
schema = make_executable_schema(Query, convert_names_case=True) | ||
schema = make_executable_schema(queries, convert_names_case=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters