Skip to content

class Input not being used on mutation with query variables  #532

Closed
@mvdwaeter

Description

@mvdwaeter

I wrote a mutation that can update the email field on a Checkout object for given checkoutId & email.

The input fields are checkoutId (custom scalar) and email (string).
The custom scalar takes the checkoutId and returns a Checkout object.

Here is the mutation:

class CheckoutEmailUpdate(Mutation):
    """
    Updates the email on an existing Checkout.
    """
    class Input:
        checkout_id = NodeID(required=True)
        email = graphene.String(required=True)

    checkout = graphene.Field(Checkout)

    @staticmethod
    def mutate(root, args, context, info):
        input = args.get('input')
        checkout = input.get('checkout_id')
        checkout.email = input.get('email')
        checkout.save(update_fields=['email'])
        return CheckoutEmailUpdate(checkout=checkout)

The NodeID is a custom scalar I created so that when you enter the mutate function; args.get('input').get('checkout_id') returns a Checkout object instead of a string.

I get the Checkout object when execute the following query:

mutation{
checkoutEmailUpdate(
  input: {
    checkoutId: "Q2hlY2tvdXQ6NWVhYTNjNTItZTMyZC00MmI4LWFkYjUtYTQ4MTZhMWQzNWJm",
    email: "[email protected]"
  }
){
checkout{
  id
  email
}
}}

But the Checkout object is not given (just a plain string), because the Input class is being ignored, when using the following query (note that I used query variables now):

mutation CheckoutEmailUpdate($input: CheckoutEmailUpdateInput!) {
        checkoutEmailUpdate(input: $input) {
            checkout {
                id
                email
            }
            userErrors {
                field
                message
            }
        }
    }

and query variables:

{
    "checkoutId": "Q2hlY2tvdXQ6NWVhYTNjNTItZTMyZC00MmI4LWFkYjUtYTQ4MTZhMWQzNWJm",
    "email": "[email protected]"
}

I'm using graphene==1.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions