Комбинированные мутации в одном из клубничных графиков
<@strawberry.type класс Мутация: @strawberry.mutation def login(self, email: str, password: str) -> LoginResult:
@strawberry.type класс Мутация: @strawberry.mutation def create_post(self, title: str, text: str) -> CreatePostResult:
schema = strawberry.Schema(mutations = ....)
Чтобы объединить несколько мутаций, создайте один класс Mutation
и дайте ему несколько методов, каждый из которых аннотирован @strawberry.mutation
:
@strawberry.type
class Mutation:
@strawberry.mutation
def login(self, email: str, password: str) -> LoginResult:
pass
@strawberry.mutation
def create_post(self, title: str, text: str) -> CreatePostResult:
pass
# Finally register both Mutation and Query (if defined) to the schema:
schema = strawberry.Schema(query=Query, mutation=Mutation)
Аналогично, чтобы объединить несколько запросов, создайте один класс Query
и дайте ему несколько fields
:
@strawberry.type
class Query:
name: str
stock: int
<
Вернуться на верх
import strawberry
@strawberry.type
class Query:
hi: str
@strawberry.type
class Mutation1:
@strawberry.mutation
def login(self, email: str, password: str) -> str:
return "hi"
@strawberry.type
class Mutation2:
@strawberry.mutation
def create_post(self, title: str, text: str) -> str:
...
@strawberry.type
class Mutation(Mutation1, Mutation2):
...
schema = strawberry.Schema(query=Query, mutation=Mutation)
Вот пример на игровой площадке: https://play.strawberry.rocks/?gist=a9117f949453d980f3d88bf88462fd30