We’re migrating all of our code from REST to graphql and the only hangup so far has been creating a new customer address and saving it as default.
In REST the default option was passed with the call, however with graphql this is a whole separate mutation customerUpdateDefaultAddress
.
Is there an easy way to retrieve the id of the most recently created address or is the only option to filter by comparing the old list of addresses with the new list?
If you are using the customer update method, you can query the addresses as part of the return values, example linked customerUpdate - GraphQL Admin
Which you could then use in a second call to update the default address.
Is there a way to retrieve only the id of the newly created address via this method? That’s where it get’s a little complicated, there will be an array of addresses but I want to specifically grab the newest one to set as default. I’m not seeing any sort of identifier (createdAt, updatedAt, etc…) to use other than to grab a list of ids before and after then comparing.
I would check how the AddressesV2 connection is sorted, as it gives you an option to reverse the sorting, which means they are sorting it on something.
I would give that a test to see if its sorting them from newest to oldest.
Also to note, the customer could be placing orders at the same time as your mutation so you might want to validate the address value is the one you want to set as default anyway.
1 Like