-
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.
feat: init strawberry logic and architecture
- Loading branch information
1 parent
99608ef
commit 67c0d23
Showing
8 changed files
with
70 additions
and
43 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,13 @@ | ||
import strawberry | ||
|
||
from src.business_logic.favoris.get_favoris import get_favoris_by_user_id | ||
from src.business_logic.formation.scrap.types import FormationsWithTotal | ||
|
||
# https://strawberry.rocks/docs/integrations/flask#options | ||
|
||
|
||
@strawberry.type | ||
class FavorisResolver: | ||
get_favoris_by_user_id: FormationsWithTotal = strawberry.field( | ||
resolver=get_favoris_by_user_id | ||
) |
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 src.business_logic.formation.get_formation_details import ( | ||
FormationDetails, | ||
get_formation_by_id, | ||
) | ||
import strawberry | ||
|
||
|
||
@strawberry.type | ||
class FormationResolver: | ||
get_formation_by_id: FormationDetails = strawberry.field( | ||
resolver=get_formation_by_id | ||
) |
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,28 +1,22 @@ | ||
import typing | ||
from src.business_logic.formation.get_formation_details import ( | ||
Formation, | ||
get_formation_by_id, | ||
) | ||
from src.models import User | ||
from src.api.favoris.favori_resolver import FavorisResolver | ||
from src.api.formation.formation_resolver import FormationResolver | ||
import strawberry | ||
|
||
from src import db | ||
|
||
|
||
@strawberry.type | ||
class Book: | ||
title: str | ||
author: str | ||
|
||
from strawberry.tools import merge_types | ||
from strawberry.extensions import QueryDepthLimiter | ||
from strawberry.extensions import MaxTokensLimiter | ||
from strawberry.extensions import MaxAliasesLimiter | ||
|
||
def get_users(): | ||
return db.session.query(User).all() | ||
types: tuple = (FormationResolver, FavorisResolver) | ||
|
||
Queries = merge_types("Queries", types) | ||
|
||
@strawberry.type | ||
class Query: | ||
users: typing.List[User] = strawberry.field(resolver=get_users) | ||
formation: Formation = strawberry.field(resolver=get_formation_by_id) | ||
|
||
|
||
schema = strawberry.Schema(Query) | ||
schema = strawberry.Schema( | ||
query=Queries, | ||
extensions=[ | ||
QueryDepthLimiter(max_depth=10), | ||
MaxTokensLimiter(max_token_count=1000), | ||
MaxAliasesLimiter(max_alias_count=15), | ||
], | ||
) | ||
# https://strawberry.rocks/docs/guides/tools |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
from dataclasses import dataclass | ||
|
||
import strawberry | ||
|
||
from src.models.formation import Formation | ||
|
||
|
||
@dataclass | ||
@strawberry.type | ||
class Facet: | ||
key: str | ||
doc_count: int | ||
|
||
|
||
@dataclass | ||
@strawberry.type | ||
class FormationIsFavorite: | ||
formation: Formation | ||
is_favorite: bool | ||
|
||
|
||
@dataclass | ||
@strawberry.type | ||
class FormationsWithTotal: | ||
total: int | ||
formations: list[Formation | FormationIsFavorite] |
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