strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Mutation Namespaces

Open LeaveMyYard opened this issue 3 years ago • 3 comments
trafficstars

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

LeaveMyYard avatar Feb 08 '22 11:02 LeaveMyYard

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.

patrick91 avatar Feb 11 '22 17:02 patrick91

relevant: https://discord.com/channels/625400653321076807/631489012632125440/908666876089995284

magicmark avatar Feb 22 '22 16:02 magicmark

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,
)

sambadi avatar Jul 19 '22 21:07 sambadi

I'm going to close this issue since there's a way to do this, even if it is not recommended 😊

patrick91 avatar Oct 20 '22 18:10 patrick91