refactor: Make sort handling mode-aware and consistent

What does this MR do and why?

Resolves #125 (closed).

The current sort implementation has an inconsistency between standard and analytics modes:

  • In standard mode, graphql_sort_value returns both the sort field identifier and direction combined (e.g. CREATED_AT_DESC), and codegen passes it through directly as the sort: parameter.
  • In analytics mode, graphql_sort_value returns only the identifier (e.g. acceptanceRate), and codegen reads sort.order separately to append direction manually.

This MR refactors sort handling so that:

  1. graphql_sort_value consistently returns only the sort identifier across all modes and sources.
  2. Codegen is responsible for appending direction in all cases, using the new SortOrder::graphql_direction() helper.
  3. types/sort.rs is the single source of truth for direction formatting (ASC/DESC).

Changes

  • src/types/sort.rs: Added SortOrder::graphql_direction() method returning "ASC" or "DESC". Removed Sort::format_graphql_value() which mixed identifier and direction concerns and is no longer needed.
  • src/analyzer/sources/merge_requests.rs, work_items.rs, projects.rs: Updated graphql_sort_value to return only the identifier (e.g. "CREATED_AT" instead of "CREATED_AT_DESC").
  • src/codegen/graphql/standard.rs: Updated to append direction via sort.order.graphql_direction() when building the sort: filter.
  • src/codegen/graphql/analytics.rs: Updated to use sort.order.graphql_direction() instead of a manual SortOrder::Descending comparison, removing the SortOrder import.

How to set up and validate locally

  1. Build and run tests:

    cargo test
  2. Verify sort tests still pass (these cover all standard mode sort combinations):

    cargo test --test sort_tests
  3. Verify code suggestion analytics sort still works:

    cargo test --test code_suggestion_tests test_code_suggestion_with_sort

Merge request reports

Loading
Loading