strawberry
strawberry copied to clipboard
Mutation Namespaces
Haven't seen this possibility implemented in Strawberry, nor have I found any existing issues.
The idea of mutation namespaces is basically to make a possibility for this mutation:
mutation {
likeArticle(id: 15) {
id
name
}
}
To be designed like this:
mutation {
article {
like(id: 15) {
id
name
}
}
}
I have tried to implement this by making types inside mutation, but it didn't work. Maybe I have done something wrong or this is not a part of Strawberry?
Also, here is the link with more info about it
hi @LeaveMyYard this might work in Strawberry, but I have never tried :)
usually nested mutations are discouraged due to how the execution is handled, from the spec: https://spec.graphql.org/June2018/#sec-Mutation
It is expected that the top level fields in a mutation operation perform side‐effects on the underlying data system. Serial execution of the provided mutations ensures against race conditions during these side‐effects.
relevant: https://discord.com/channels/625400653321076807/631489012632125440/908666876089995284
I have tried to implement this like present below and this code is work under the latest version of strawberry.
@strawberry.type
class Query:
@strawberry.field
def hello_world(self) -> str:
return f"Hello, world!"
@strawberry.type
class MyCollection:
@strawberry.field
def action(self, name: str) -> str:
return f"Hello, {name}"
@strawberry.type
class Mutation:
@strawberry.field
def my_collection(self) -> MyCollection:
return MyCollection()
schema = strawberry.federation.Schema(
query=Query,
mutation=Mutation,
)
I'm going to close this issue since there's a way to do this, even if it is not recommended 😊