-
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
4 changed files
with
61 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from . import groups, hello, users | ||
|
||
queries = [ | ||
groups.Query, | ||
hello.Query, | ||
users.Query, | ||
] |
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 |
---|---|---|
@@ -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) |
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 |
---|---|---|
@@ -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!" |
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 |
---|---|---|
@@ -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") |