Sort or OrderBy an object inside the object array with graph and API, possible?

Hello everyone,

this might be a silly question maybe, I am not a graph expert, but… wanted to know if is possible to sort my query here:

query Models($locale: SiteLocale) {
  allCatalogColours (locale: $locale, first: 100, orderBy: colorName_ASC){
    colorName
slug
colourDescription
colourHex {
  hex
}
colourSerie
familyColour {
  nameFamily
  id
}
id
secondaryColour
relatedModels {
  id
  modelName
  index
}
imageDisplay {
  url
  filename
}
  }
}

Exactly this part

relatedModels {
  id
  modelName
  index
}

by the index field, which basically is a type of fav range, introduced manually by the editors. So I return the fields in that exact order.

Also asking about graph side, because I tried with vue 3, but no luck. I have this specific part in a “v-for” so for “v-for model in colour.relatedModels”. Was basically trying something “super experimental” that actually don’t know if I should be doing it , but at the end it didn’t work anyways

                <span
                  **v-for="model in sortIndex(colour.relatedModels)"**
                  :key="model.id"
                  :style="{ color: colour.colourHex.hex }">
                 <span style="color:#000"> {{model.index}}</span>
                    <pill-search
                    @pushUp="pushUp($event)"
                    :primColor="colour.primaryColour"
                    :secColor="colour.secondaryColour"
                    :slug="colour.slug"
                    :modelName="model.modelName"
                    ></pill-search>
                </span>

where sortIndex is a method that returns:

return _.orderBy(arrayModels, [arrayModels.index]);

And I’m probably going to have all the “the vue gods” ripping their clothes off after reading this.

So any help or advise will be helpful

I think that the lodash approach is fine, have you tried passing 'index' rathern than arrayModels.index? As the item on which to order?

If you print the relatedModels before iterating on them? Are they ordered?

Hello mat_jack1, sorry for the delay, thank you for the answer :slight_smile: . And no, they are not orderer, also the reason why I am passing arrayModels.index is because this index field, contains the exact position, which is not the normal index, they want to be able to change and sort this by themselves based on the “popularity” of the model