Giter Site home page Giter Site logo

Comments (1)

bellini666 avatar bellini666 commented on August 17, 2024

Hrm, we could create a resolvers.aupdate, which basically calls update wrapped in sync_to_async.

Another possibility here would be to use gql.django.mutation with a sync function. I will automatically wrap the whole resolver in sync_to_async to make it work with ASGI. e.g.

@gql.type
class Mutation:
    @gql.django.mutation
    def update_user(self, info: Info, input: UserInputPartialInput) -> User:
        data = vars(input)
        node_id: gql.relay.GlobalID = data.pop("id")
        instance = node_id.resolve_node(info, ensure_type=UserModel)
        request_user = info.context.request.user
        if instance != request_user:
            raise PermissionError("You can only modify objects you own.")

        return resolvers.update(
            info, instance, resolvers.parse_input(info, data)
        )

Note that gql.django.mutation by default will modify your return value to be User | OperationInfo, which captures some django default errors like ValidationError/PermissionDenied and return them as OperationInfo messages. You can pass handle_django_errors=False if you don't want that

Having said all of that, do you want to try to open a PR to add those async variants to the resolvers? It should be very simple!

from strawberry-django-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.