Geo Replicables API: Add ability to sort to Geo Registries Resolver

Why are we doing this work

We are working to enhance the functionality available in the Geo Replicables List View &16585 (closed)

We would like to support the ability to sort a list by set fields. These sorts would work in tandem with the available status filters already available on the Replicables API.

Sort Options

All sorts should be asc and desc

  1. Sort by Name (field id)
  2. Sort by Last Synced At (field last_synced_at)
  3. Sort by Last Verified At (field verified_at)

Relevant links

Implementation plan

The records to be returned by the resolver depending on the query's parameters are found by the FrameworkRegistryFinder. This class orders all records by ID as default.

Following this, a proposed implementation would be:

  1. Add a sort parameter to the registries_resolver.rb:
    argument :sort, GraphQL::Types::String,
      required: false,
      description: "Sort order of results. Format: `<field_name>_<sort_direction>`, " \
        "for example: `id_desc` or `name_asc`",
      default_value: 'name_asc'
  1. Add a new order method in the FrameworkRegistryFinder:
  def sort_by(registry_entries)
    return registry_entries.ordered_by_id if params[:sort].blank? || params[:sort] == 'id'

    # Only allow certain parameters' values: last_synced_at & last_verified_at
    # Write the new method below to take this into account
    registry_entries.ordered_by(params[:sort])
  end

and use this in execute instead of ordered_by_id

  1. Write some tests :)
Edited by Chloe Fons