ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::{FusionOptions, RrfOptions};
use crate::retrieve::Fusion;

/// **THE REQUEST AND THE FOLD ARE ONE CALL APART.** A request naming the flavour and no number
/// resolves to the ruled constant, which is what keeps `Fusion::RRF_K` a law rather than a value
/// every client restates.
#[test]
fn a_flavour_named_with_no_number_resolves_to_the_ruled_constant() {
  assert_eq!(FusionOptions::rrf().fusion(), Fusion::rrf());
  assert_eq!(RrfOptions::new().damping(), Fusion::RRF_K);
}

/// A named number wins over the law, and the request keeps the fact that it was named — the two
/// readers are different questions.
#[test]
fn a_named_damping_constant_beats_the_law_and_stays_visible() {
  let asked = RrfOptions::new().with_damping(5);

  assert_eq!(asked.named_damping(), Some(5));
  assert_eq!(asked.damping(), 5);
  assert_eq!(FusionOptions::Rrf(asked).fusion(), Fusion::Rrf { k: 5 });
}

/// **`Option` HERE, BARE THERE — the de-Option law, not a mismatch.** Absence in the request DEFERS;
/// a resolved fold has no chain left to defer to.
#[test]
fn the_request_carries_absence_and_the_fold_carries_a_number() {
  assert_eq!(RrfOptions::new().named_damping(), None);

  let Fusion::Rrf { k } = FusionOptions::default().fusion();
  assert_eq!(k, Fusion::RRF_K);
}

/// A tier whose options say nothing runs the shipped fold — the same default the framework's own
/// [`Fusion`] carries, reached through this type rather than restated by it.
#[test]
fn the_default_request_is_the_shipped_fold() {
  assert_eq!(FusionOptions::default(), FusionOptions::rrf());
  assert_eq!(FusionOptions::default().fusion(), Fusion::default());
}

#[cfg(feature = "async-graphql")]
mod wire {
  use async_graphql::{EmptyMutation, EmptySubscription, Object, Schema};

  use super::super::FusionOptions;

  struct Query;

  #[Object]
  impl Query {
    async fn fused(&self, fusion: Option<FusionOptions>) -> bool {
      fusion.is_some()
    }
  }

  fn sdl() -> String {
    Schema::build(Query, EmptyMutation, EmptySubscription)
      .finish()
      .sdl()
  }

  /// **EXACTLY ONE FLAVOUR, refused at the PARSE.** The `@oneOf` directive is what moves *a tier
  /// runs one fold* out of a run-time check and into the schema — the order-by face's own mechanism,
  /// reached for the same reason.
  #[test]
  fn the_flavour_request_is_published_as_a_oneof_input_object() {
    let sdl = sdl();

    assert!(sdl.contains("input FusionOptions @oneOf {"), "{sdl}");
    assert!(sdl.contains("rrf: RrfOptions"), "{sdl}");
    assert!(
      sdl.contains("directive @oneOf on INPUT_OBJECT"),
      "the directive is declared:\n{sdl}",
    );
  }

  /// The flavour's own parameters are an ordinary input object with every field omissible — so
  /// `{ rrf: {} }` is a legal document and means *this flavour, at the ruled constants*.
  #[test]
  fn the_flavours_parameters_are_wholly_omissible() {
    let sdl = sdl();

    assert!(sdl.contains("input RrfOptions {"), "{sdl}");
    assert!(
      sdl.contains("k: Int\n"),
      "the damping constant is nullable:\n{sdl}",
    );
  }

  /// NO PROSE REACHES THE SCHEMA. Every doc line on these types is behind `cfg_attr(doc, …)`, which
  /// is what keeps generated-adjacent commentary out of a client's SDL.
  #[test]
  fn the_flavour_publishes_no_description() {
    let sdl = sdl();

    assert!(
      !sdl.contains("Reciprocal rank fusion"),
      "a doc comment reached the schema:\n{sdl}",
    );
  }
}