You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
The text was updated successfully, but these errors were encountered:
And based on that ticket I managed to fix it, by adding a parse_value to NodeID:
class NodeID(ID):
@staticmethod
def parse_literal(node):
"""
:return: Object or None
"""
if isinstance(node, StringValue):
return get_from_global_id(node.value)
@staticmethod
def parse_value(s):
"""
:return: Object or None
"""
if isinstance(s, string_types):
return get_from_global_id(s)
The mutation query without query parameters is using NodeID.parse_literal
And the second mutation query, with query parameters is using NodeID.parse_value
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:
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:
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):
I'm using graphene==1.4.1
The text was updated successfully, but these errors were encountered: