ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! **B-27 D-5 — 接口上 只能问接口里有的字段**, read back out of the emitted input faces.
//!
//! What is pinned is that the boundary is the SCHEMA's rather than a resolver's: the two types a
//! client writes carry the CONTRACT's fields and nothing else, so a member's private column is not
//! refused at run time — it is a name the published input object does not have.

use crate::{
  interface::{
    InterfaceDatabase, InterfaceField, Tier, default_filter_name, default_order_by_name,
    tests::{ident, media, tight},
  },
  model::{AliasOptions, DatabaseKind},
};

/// The two INPUT FACES alone, with their spacing removed.
///
/// The faces rather than the whole expansion, and the ABSENCE claims are why: a member's own
/// spelling of a shared column is a real name elsewhere in the emission — the query binding carries
/// it, that being where an arm aliases the member's column to the interface's — so a claim about
/// what a CLIENT can write has to be scoped to what a client reads.
///
/// Tight because the gated block is a MACRO invocation, whose body no formatter reaches.
fn emitted(model: &crate::interface::InterfaceModel) -> String {
  tight(model.input_faces())
}

/// The fixture, stored in one database so the whole wire surface is written.
fn stored() -> crate::interface::InterfaceModel {
  let mut model = media();
  model.persist = vec![InterfaceDatabase {
    kind: DatabaseKind::Sqlite,
    aliases: AliasOptions::default(),
  }];
  model
}

/// **BOTH INPUT TYPES NOW HAVE A FACE**, which is what a root field taking `where:` and `orderBy:`
/// spends — and the faces are the UNIT's, so a byte of registry construction cannot differ from the
/// record's.
#[test]
fn the_filter_and_the_order_by_wear_the_units_input_faces() {
  let model = stored();
  let emitted = emitted(&model);
  let (filter, order) = (
    default_filter_name(&model.name),
    default_order_by_name(&model.name),
  );

  assert!(
    emitted.contains(&format!(
      "impl::ingraph::__private::async_graphql::InputTypefor{filter}"
    )),
    "{emitted}"
  );
  assert!(
    emitted.contains(&format!(
      "impl::ingraph::__private::async_graphql::InputObjectTypefor{filter}"
    )),
    "{emitted}"
  );
  assert!(
    emitted.contains(&format!(
      "impl::ingraph::__private::async_graphql::InputTypefor{order}"
    )),
    "{emitted}"
  );
  assert!(
    emitted.contains(&format!(
      "impl::ingraph::__private::async_graphql::OneofObjectTypefor{order}"
    )),
    "the ORDER is a @oneOf object, so *exactly one term* is the validator's rule:\n{emitted}"
  );
}

/// **THE PUBLISHED NAMES ARE THE FRAMEWORK's**, the interface grammar carrying no rename tier for
/// either type — which is `wire_type`'s identity reading, one declaration over.
#[test]
fn the_published_names_are_the_design_vocabulary() {
  let emitted = emitted(&stored());

  assert!(emitted.contains("\"MediaFilter\""), "{emitted}");
  assert!(emitted.contains("\"MediaOrderBy\""), "{emitted}");
}

/// **D-5: THE FIELDS ARE THE CONTRACT's, AND ONLY THE CONTRACT's.** A member's private column has no
/// entry here to name, which is schema-level enforcement rather than a runtime refusal.
#[test]
fn the_faces_publish_the_contracts_own_fields_and_no_members() {
  let mut model = stored();
  // A column ONE member keeps and the contract never promised. It reaches the model the only way a
  // member-specific column ever could — it does not — so what this pins is that a contract field
  // renamed FOR one member still publishes the contract's word, and nothing of the member's.
  model.fields.push(InterfaceField {
    name: ident("frame_rate"),
    ty: syn::parse_quote!(u32),
    tier: Tier::Stored,
    marker: None,
    copy: true,
    pins: Vec::new(),
    wire: None,
    operands: Vec::new(),
    members: vec![crate::interface::MemberColumn {
      variant: ident("Audio"),
      column: ident("sample_rate"),
    }],
  });
  let emitted = emitted(&model);

  assert!(emitted.contains("\"frameRate\""), "{emitted}");
  assert!(
    !emitted.contains("\"sampleRate\""),
    "a member's own spelling of a shared column is never a client's word:\n{emitted}"
  );
  assert!(
    !emitted.contains("\"flags\""),
    "nor is `Audio`'s name for the `mask` column:\n{emitted}"
  );
}

/// **AND THE COMPUTED TIER IS STILL ABSENT** from both — a computed value is derived from a member's
/// wire OUTPUT and is a column nowhere, so neither a predicate nor an `ORDER BY` can name one.
#[test]
fn a_computed_field_reaches_neither_input_face() {
  let emitted = emitted(&stored());

  assert!(emitted.contains("\"title\""), "{emitted}");
  assert!(
    !emitted.contains("\"displayLabel\""),
    "the computed tier is statically absent, and the absence IS the refusal:\n{emitted}"
  );
  assert!(!emitted.contains("\"checksum\""), "{emitted}");
}

/// The faces ride the BINDING GATE, so a build with no GraphQL library carries the two types and no
/// impl naming a library it does not have.
#[test]
fn the_input_faces_ride_the_binding_gate() {
  let emitted = emitted(&stored());

  assert!(
    emitted.contains("::ingraph::__private::gate::if_async_graphql!"),
    "{emitted}"
  );
}