GraphQL returns null address if optional telephone is set as empty string
-
11-05-2021 - |
Question
Steps to reproduce
Using GraphQL mutation, add a product to Cart
Set Shipping Addresses on cart using the following Mutation
mutation {
setShippingAddressesOnCart(
input: {
cart_id: "zcatHMtPLY8M8hs0I1ALNihsk8bdRlUI"
shipping_addresses: [
{
address: {
firstname: "Bob"
lastname: "Roll"
company: "Magento"
street: ["Magento Pkwy", "Main Street"]
city: "Austin"
region: "AN"
region_id: 533
postcode: "78758"
country_code: "IN"
telephone: "" #<---- note that the telephone is an empty string.
save_in_address_book: false
},
}
]
}
) {
cart {
shipping_addresses {
firstname
lastname
company
street
city
region {
code
label
}
postcode
telephone
country {
code
label
}
pickup_location_code
}
}
}
}
Response:
{
"data": {
"setShippingAddressesOnCart": {
"cart": {
"shipping_addresses": []
}
}
}
}
I've tried few things but they didn't work, Does any knows how to resolve it?
Solution
Resolved by adding following schema.graphqls
interface CartAddressInterface @typeResolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartAddressTypeResolver") {
firstname: String!
lastname: String!
company: String
street: [String!]!
city: String!
region: CartAddressRegion
postcode: String
country: CartAddressCountry!
telephone: String
}
input CartAddressInput {
firstname: String!
lastname: String!
company: String
street: [String!]!
city: String!
region: String
region_id: Int
postcode: String
country_code: String!
telephone: String
save_in_address_book: Boolean @doc(description: "Determines whether to save the address in the customer's address book. The default value is true")
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange