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
//! The holding adapter, read at the three places a bare return and a crossed one disagree.
//!
//! The refusal a type with NO crossing row earns is a compile-level claim and is pinned as a
//! `compile_fail` doctest on [`Crossed`] itself: this module is `cfg(test)`, so rustdoc never reads
//! it and a doctest written here would be a pin that never runs.

use async_graphql::OutputType;

use super::Crossed;

/// What a schema READS off a form — the name and its nullability together, which is the pair a
/// field's SDL line is written from.
fn published<T: OutputType>() -> String {
  <T as OutputType>::qualified_type_name()
}

/// **THE ADAPTER IS INVISIBLE IN THE SDL.** Every name is the projection's, so what a client sees is
/// decided by the crossing map and never by the position the value came from.
#[test]
fn the_adapter_publishes_the_projections_own_name() {
  assert_eq!(<Crossed<u128> as OutputType>::type_name(), "u128");
  assert_eq!(<Crossed<u32> as OutputType>::type_name(), "u32");
  assert_eq!(<Crossed<String> as OutputType>::type_name(), "String");
}

/// **HELD AND WRAPPED RENDER ALIKE**, which is the whole of what this type was minted for: the form
/// a face returns by BORROWING storage and the form it returns by MOVING a value it made are one
/// schema type, at every row where the two used to disagree.
///
/// The three rows are the disagreements measured on the rewrite tier — a width async-graphql has no
/// scalar for at all, a blob whose bare face answers a different question, and a text column that
/// already agreed and must go on agreeing.
#[test]
fn a_crossed_value_publishes_what_a_borrowed_one_publishes() {
  // The width with no `OutputType` row anywhere: a bare return does not compile, and this does.
  assert_eq!(
    published::<Crossed<u128>>(),
    published::<<u128 as super::ToGraphqlOutput>::Output<'static>>(),
  );
  // The blob, whose bare face is `[Int!]!` — a thumbnail as a list of small integers.
  assert_eq!(published::<Crossed<Vec<u8>>>(), "U8Vector!");
  assert_ne!(published::<Crossed<Vec<u8>>>(), published::<Vec<u8>>());
  // The row that already agreed, pinned so it goes on agreeing.
  assert_eq!(published::<Crossed<String>>(), published::<String>());
}

/// **A NULLABLE COLUMN STAYS NULLABLE.** `qualified_type_name` is delegated rather than defaulted,
/// and this is the difference: the default appends `!` to the type name, where `Option`'s own row
/// publishes the bare one.
#[test]
fn an_optional_value_publishes_nullable() {
  assert_eq!(published::<Crossed<Option<u128>>>(), "u128");
  assert_eq!(published::<Crossed<u128>>(), "u128!");
  assert_eq!(published::<Crossed<Option<String>>>(), "String");
  assert_eq!(published::<Crossed<Option<Vec<u8>>>>(), "U8Vector");
}

/// **THE VALUE SURVIVES THE MOVE**, which is the half a name assertion cannot show: the adapter
/// holds what it was given and the crossing runs on a borrow of that, once.
#[test]
fn the_adapter_holds_the_value_it_was_handed() {
  let held = Crossed(u128::MAX);
  assert_eq!(held.0, u128::MAX);
  assert_eq!(
    <u128 as super::ToGraphqlOutput>::to_graphql_output(&held.0),
    crate::U128::from(u128::MAX),
  );
}