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
- Sort by Name (field
id) - Sort by Last Synced At (field
last_synced_at) - Sort by Last Verified At (field
verified_at)
Relevant links
- Base resolver for Geo Replicables:
registries_resolver.rb - Example of resolver that supports sorting
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:
- Add a
sortparameter to theregistries_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'
- 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
- Write some tests :)
Edited by Chloe Fons