-
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
14 changed files
with
352 additions
and
7 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,2 +1,2 @@ | ||
[MESSAGES CONTROL] | ||
disable=C0114, C0115, C0116, W0613, W0622 | ||
disable=C0114, C0115, C0116, R0801, R0903, W0613, W0622 |
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
Empty file.
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,24 @@ | ||
from typing import Any | ||
|
||
from ariadne_graphql_modules import GraphQLInterface | ||
|
||
from ..models.group import Group | ||
from ..models.post import Post | ||
from ..models.user import User | ||
|
||
|
||
class SearchResultInterface(GraphQLInterface): | ||
summary: str | ||
|
||
@staticmethod | ||
def resolve_type(obj: Any, *_) -> str: | ||
if isinstance(obj, Group): | ||
return "Group" | ||
|
||
if isinstance(obj, Post): | ||
return "Post" | ||
|
||
if isinstance(obj, User): | ||
return "User" | ||
|
||
raise TypeError(f"Unsupported type: {type(obj)}") |
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,12 +1,14 @@ | ||
from typing import Any | ||
|
||
from . import calendar, categories, groups, hello, posts, users | ||
from . import calendar, categories, groups, hello, models, posts, search, users | ||
|
||
queries: Any = [ | ||
calendar.Query, | ||
categories.Query, | ||
groups.Query, | ||
hello.Query, | ||
models.Query, | ||
posts.Query, | ||
search.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,21 @@ | ||
from typing import Any | ||
|
||
from ariadne_graphql_modules import GraphQLObject | ||
from graphql import GraphQLResolveInfo | ||
|
||
from ..database import db | ||
from ..unions.model import Model | ||
|
||
|
||
class Query(GraphQLObject): | ||
@GraphQLObject.field(graphql_type=list[Model]) | ||
@staticmethod | ||
async def models(obj, info: GraphQLResolveInfo) -> list[Any]: | ||
results: list = [] | ||
|
||
results += await db.get_all("categories") | ||
results += await db.get_all("groups") | ||
results += await db.get_all("posts") | ||
results += await db.get_all("users") | ||
|
||
return results |
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,32 @@ | ||
from typing import Any | ||
|
||
from ariadne_graphql_modules import GraphQLObject | ||
from graphql import GraphQLResolveInfo | ||
|
||
from ..database import db | ||
from ..interfaces.search_result import SearchResultInterface | ||
|
||
|
||
class Query(GraphQLObject): | ||
@GraphQLObject.field(graphql_type=list[SearchResultInterface]) | ||
@staticmethod | ||
async def search(obj, info: GraphQLResolveInfo, *, query: str) -> list[Any]: | ||
query = query.strip() | ||
if not query: | ||
return [] | ||
|
||
results: list = [] | ||
|
||
for group in await db.get_all("groups"): | ||
if query in group.name.lower(): | ||
results.append(group) | ||
|
||
for post in await db.get_all("posts"): | ||
if query in post.message.lower(): | ||
results.append(post) | ||
|
||
for user in await db.get_all("users"): | ||
if query in user.username.lower(): | ||
results.append(user) | ||
|
||
return results |
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
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
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
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
Empty file.
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,32 @@ | ||
from typing import Any | ||
|
||
from ariadne_graphql_modules import GraphQLUnion | ||
|
||
from ..models.category import Category | ||
from ..models.group import Group | ||
from ..models.post import Post | ||
from ..models.user import User | ||
from ..types.category import CategoryType | ||
from ..types.group import GroupType | ||
from ..types.post import PostType | ||
from ..types.user import UserType | ||
|
||
|
||
class Model(GraphQLUnion): | ||
__types__ = (CategoryType, GroupType, PostType, UserType) | ||
|
||
@staticmethod | ||
def resolve_type(obj: Any, *_) -> str: | ||
if isinstance(obj, Category): | ||
return "Category" | ||
|
||
if isinstance(obj, Group): | ||
return "Group" | ||
|
||
if isinstance(obj, Post): | ||
return "Post" | ||
|
||
if isinstance(obj, User): | ||
return "User" | ||
|
||
raise TypeError(f"Unsupported type: {type(obj)}") |
Oops, something went wrong.