How can I append element to array wiht graphql

Thanks @Wisgon… BTW for anyone searching manipulating arrays in graphql, an idiom I’ve developed is to chain mutations in an update to first clear arrays, then “rewrite” them, for instance:

mutation updateLocation($id: ID!, $location: LocationPatch!) {
  # clear existing address lines (ensure new/existing lines are in LocationPatch)
  clearAddressesLines: updateLocation(input: {filter: {id: [$id]}, remove: {addresses: [""]}}) {
    location {
      id
    }
  }
  updateLocation(input: {filter: {id: [$id]}, set: $location}) {
    location {
      id
      addresses
      locality
      region
      postcode
    }
  }
}

1 Like