Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to return nothing or boolean in mutations? #497

Closed
alexche8 opened this issue Jul 4, 2017 · 3 comments
Closed

Is there any way to return nothing or boolean in mutations? #497

alexche8 opened this issue Jul 4, 2017 · 3 comments

Comments

@alexche8
Copy link

alexche8 commented Jul 4, 2017

Want to create simple mutation that returns null or True like described there
ardatan/graphql-tools#277 (comment)

Can someone provide example in graphql-python of that query?

type Mutation {
  forgottenPassword(email: String!): Boolean
}
@waxisien
Copy link

waxisien commented Jul 5, 2017

Hi, something like this :

class ForgottenPassword(graphene.Mutation):
    class Input:
        email = graphene.String(required=True)

    ok = graphene.Boolean()

    @staticmethod
    def mutate(root, args, context, info):
        print 'Send email to ', args['email']
        return ForgottenPassword(ok=True)


class MyMutations(graphene.ObjectType):
    forgotten_password = ForgottenPassword.Field()

Look at http://docs.graphene-python.org/en/latest/types/mutations/

@alexche8
Copy link
Author

alexche8 commented Jul 5, 2017

Got it, thanks.

@gonzalezzfelipe
Copy link

I'll leave this here in case it is useful for someone. What I wanted to implement is for the payload to directly be the boolean, and I got to do it by writing:

class ForgottenPassword(graphene.Mutation):
    class Input:
        email = graphene.String(required=True)

    Output = graphene.Boolean

    @staticmethod
    def mutate(root, args, context, info):
        print 'Send email to ', args['email']
        return True


class MyMutations(graphene.ObjectType):
    forgotten_password = ForgottenPassword.Field()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants