ingraph-derive 0.1.0

The attribute and derive macros for ingraph: the words a record, node, key, filter and vocabulary declaration is written in.
Documentation
//! THE RESEAT — the seat `sortable` left, the seats it may not take, and the one it took.
//!
//! Ruled (ii) by the user on 2026-08-12, during PR #248's review, and recorded as **B-29** on the
//! comment-dump issue #238: the word moves out of the label and into the persist container as a
//! bare ALL-DB word — `#[ingraph(list(scalar), sortable)]` — composing with a per-database
//! storage block as `persist(sortable, postgres(edge))`. The measurement behind it was a consumer
//! census: every reader of the fact is storage- or lowering-side (the DDL companion, `SqlWrite`'s
//! `SHADOWS`, the ORDER lowering, the cursor slot), and the wire face deliberately never read it.
//!
//! # ONE SPELLING, so this suite is where the DEAD one is pinned
//!
//! `list(scalar, sortable)` does not survive as an alias. It is a TEACHING refusal pointing into
//! `persist(…)` — the shape a word that was legal one ruling ago takes here, `write`'s move into
//! `poll(…)` being the precedent — because an author carrying the old spelling has the right idea
//! and needs one word moved, not the label vocabulary's list of families the word is not one of.
//!
//! # …and NOT per database, which is the other half of the ruling
//!
//! One intent, from which each database derives its own mechanism: a native-array dialect orders
//! the collection itself and mints nothing, an edge-storing one mints the companion. A per-database
//! seat would double-book with `edge`, the word that already says which storage form a database
//! takes, and a client's written order has to fingerprint alike whichever form answered it.
//!
//! The word's own grammar — where it is read, what it resolves to, the reading it does not touch —
//! is [`crate::sortable_tests`]. What is asserted HERE is only the move.

use ingraph_codegen::prelude::*;

use crate::{host, parse::parse};

/// The refusals one declaration gets, joined — several, because a reseat's fixtures write the dead
/// spelling more than once and every one of them is answered.
fn refused(input: &syn::DeriveInput) -> String {
  let (host, options) = host::split(input);
  parse(&host, &options, NodeKind::Record)
    .err()
    .map(|error| {
      error
        .into_iter()
        .map(|error| error.to_string())
        .collect::<Vec<_>>()
        .join(" | ")
    })
    .unwrap_or_else(|| panic!("this declaration is refused"))
}

/// **THE OLD SEAT IS A TEACHING REFUSAL**, naming the container the word moved to and the whole new
/// spelling — not an alias, and not the unknown-element sentence.
#[test]
fn the_label_spelling_teaches_the_new_seat() {
  let message = refused(&syn::parse_quote! {
    #[ingraph(sqlite, graphql(async_graphql))]
    struct S {
      #[ingraph(id)] id: u128,
      #[ingraph(list(string, sortable))] tags: Vec<String>,
    }
  });
  assert!(
    message.contains("is the FIELD's own word now")
      && message.contains("#[ingraph(list(scalar), sortable)]"),
    "the refusal names the seat and the spelling: {message}"
  );
}

/// **AND IT IS THE SAME SENTENCE WHEREVER THE LABEL WROTE IT** — beside an element, before one, and
/// on a family that never took it. The word left the label; which label it left is not a second
/// rule.
#[test]
fn every_label_seat_gets_the_one_sentence() {
  for declaration in [
    syn::parse_quote! {
      #[ingraph(sqlite, graphql(async_graphql))]
      struct S {
        #[ingraph(id)] id: u128,
        #[ingraph(list(sortable, string))] tags: Vec<String>,
      }
    },
    syn::parse_quote! {
      #[ingraph(sqlite, graphql(async_graphql))]
      struct S {
        #[ingraph(id)] id: u128,
        #[ingraph(set(string, sortable))] notes: Vec<String>,
      }
    },
    syn::parse_quote! {
      #[ingraph(sqlite, graphql(async_graphql))]
      struct S {
        #[ingraph(id)] id: u128,
        #[ingraph(string(sortable))] title: String,
      }
    },
    syn::parse_quote! {
      #[ingraph(sqlite, graphql(async_graphql))]
      struct S {
        #[ingraph(id)] id: u128,
        #[ingraph(list(sortable))] tags: Vec<String>,
      }
    },
  ] {
    let declaration: syn::DeriveInput = declaration;
    let message = refused(&declaration);
    assert!(
      message.contains("is the FIELD's own word now"),
      "the label's every seat teaches one move: {message}"
    );
  }
}

/// **THE WORD IS REFUSED INSIDE A DATABASE'S BLOCK**, by name, with the common scope it belongs to
/// — the ruling's *explicitly NOT per-db* half, stated where it would be broken.
#[test]
fn a_database_block_refuses_the_word_into_the_common_scope() {
  let message = refused(&syn::parse_quote! {
    #[ingraph(postgres, graphql(async_graphql))]
    struct S {
      #[ingraph(id)] id: u128,
      #[ingraph(list(scalar), postgres(sortable))] marks: Vec<i64>,
    }
  });
  assert!(
    message.contains("ONE intent for every database")
      && message.contains("#[ingraph(sortable, postgres(…))]"),
    "the refusal names the dialect-free seat: {message}"
  );
}

/// **A KEY-SIDE COLUMN IS REFUSED** — the shape the old seat could not reach, and the one seat at
/// which nothing else answers.
///
/// The word used to be written inside a collection's own parentheses, so a collection came with it.
/// At the new seat it can stand on a field whose vocabulary is the sealed `Id` trait, where the
/// mandatory-kind rule deliberately says nothing — so without this the word would mirror nothing in
/// silence.
#[test]
fn a_key_side_column_is_refused_the_word() {
  let message = refused(&syn::parse_quote! {
    #[ingraph(sqlite, graphql(async_graphql))]
    struct S {
      #[ingraph(id, sortable)] id: u128,
      #[ingraph(list(string))] tags: Vec<String>,
    }
  });
  assert!(
    message.contains("a KEY-SIDE column declares no label at all"),
    "the refusal names what is missing: {message}"
  );
}

/// **AND A DATA FIELD WITH NO LABEL IS ANSWERED HERE**, where this seat used to defer.
///
/// The claim was that the mandatory-kind rule already named the very word the storage word waits
/// for, so this seat added no second sentence about one mistake. That rule went with the
/// participation inversion — an unlabelled column resolves through `<T as DefaultMarker>::Marker` at
/// the type level, and a type with no row there is an `E0277` naming the type — so deferring would
/// leave `sortable` beside no collection word with no sentence at all. The one sentence is this
/// seat's own now, and it is still one.
#[test]
fn an_unlabelled_data_field_keeps_the_one_sentence() {
  let message = refused(&syn::parse_quote! {
    #[ingraph(sqlite, graphql(async_graphql, plural = "many"))]
    struct S {
      #[ingraph(id)] id: u128,
      #[ingraph(sortable)] tags: Vec<String>,
    }
  });
  assert!(
    message.contains("`sortable` orders a COLLECTION")
      && message.contains("this column names no family at all")
      && message.contains("`#[ingraph(list(scalar), sortable)]`"),
    "the word with nothing to order names what would give it something: {message}"
  );
  assert!(
    !message.contains("carries a face and declares no KIND"),
    "and the rule it deferred to is gone rather than silent: {message}"
  );
  assert!(
    !message.contains("a KEY-SIDE column declares no label"),
    "and it is this field's own sentence — the key-side one is TRUE and about another field, so \
     reusing it here would tell an author looking at a `Vec<String>` a rule they are not breaking: \
     {message}"
  );
}

/// **AND A PATH MARKER IS REFUSED**, which the grammar used to answer by construction: the word sat
/// inside a collection's parentheses and `label = "…"` has none.
#[test]
fn a_path_marker_cannot_carry_the_word() {
  let message = refused(&syn::parse_quote! {
    #[ingraph(sqlite, graphql(async_graphql, plural = "many"))]
    struct S {
      #[ingraph(id)] id: u128,
      #[ingraph(label = "their::RollMarker", sortable)] roll: Roll<Tag>,
    }
  });
  assert!(
    message.contains("a path is a name here, not a family"),
    "the refusal says why a path cannot answer: {message}"
  );
}

/// **THE READING IS UNTOUCHED BY THE MOVE.** The marker a declaration resolves to is the element
/// word's answer and nothing else, so the word's new container reaches no filter — which is the
/// same fence the word carried at its old seat, now proved across the seat change.
#[test]
fn the_marker_is_what_it_was_before_the_word_moved() {
  let markers = |declaration: syn::DeriveInput| {
    let (host, options) = host::split(&declaration);
    let model = parse(&host, &options, NodeKind::Record).expect("a legal declaration");
    format!(
      "{:?}",
      model
        .fields
        .iter()
        .map(|field| &field.marker)
        .collect::<Vec<_>>()
    )
  };

  let asked = markers(syn::parse_quote! {
    #[ingraph(sqlite, graphql(async_graphql, plural = "many"))]
    struct S {
      #[ingraph(id)] id: u128,
      #[ingraph(list(string), sortable)] tags: Vec<String>,
    }
  });
  let plain = markers(syn::parse_quote! {
    #[ingraph(sqlite, graphql(async_graphql, plural = "many"))]
    struct S {
      #[ingraph(id)] id: u128,
      #[ingraph(list(string))] tags: Vec<String>,
    }
  });
  assert_eq!(asked, plain, "the storage word reaches no interpretation");
}