Skip to main content

InterfaceModel

Struct InterfaceModel 

Source
pub struct InterfaceModel {
Show 14 fields pub prefix: EmissionPrefix, pub vis: Visibility, pub name: Ident, pub krate: Path, pub members: Vec<UnionMember>, pub fields: Vec<InterfaceField>, pub error: Option<Ident>, pub computed_error: Option<Path>, pub persist: Vec<InterfaceDatabase>, pub errors: Vec<InterfaceError>, pub operand_errors: Vec<InterfaceError>, pub plural: Option<String>, pub connection: Option<String>, pub edge: Option<String>,
}
Expand description

One interface’s declaration, validated.

Public fields for the reason RecordModel’s are: nothing here parses, so a front end that is not the derive builds the same struct and reaches the same emitter.

Fields§

§prefix: EmissionPrefix

The EMISSION NAMESPACE this declaration’s minted names wear.

EmissionPrefix::INGRAPH for everything ingraph’s own front ends build, and a domain framework’s own mark for a model mediagraph-codegen or its successors build — see crate::prefix for what the seat covers and why it is a field rather than a constant.

§vis: Visibility

The declaration’s visibility, which every emitted item takes.

§name: Ident

The declared enum’s own name.

§krate: Path

The path to the ingraph crate itself — ::ingraph unless #[ingraph(crate = "…")] named another.

§members: Vec<UnionMember>

Its members, in declaration order. Never empty, and never two of one type.

The UNION’s own member type, because a member is the same thing in both declarations: the variant that names it and the type it carries. Sharing it is what lets one seam equip both.

§fields: Vec<InterfaceField>

The fields every member promises, in declaration order.

§error: Option<Ident>

What the emitted REFUSAL type is called, when the declaration named it.

None is <Interface>UnwrapError, which is what InterfaceModel::error resolves.

§computed_error: Option<Path>

graphql(computed(error = "…")) — the type every FALLIBLE computed field answers with.

ONE cell and DB-LESS, which is the ruled exception to this grammar’s database blocks: a computed value is derived from the member rather than read out of a row, so the crossing names no database and there is nothing for a per-database cell to differ about. None is the boxed refusal — see InterfaceModel::computed_error.

§persist: Vec<InterfaceDatabase>

The databases the interface’s own persist(…) block named, in the order they were written.

A SELECTION rather than a storage declaration: an interface owns no table, so what this does is say which databases the row equations are checked at. A field’s own per-database pin names one too, and InterfaceModel::databases is where the two are joined.

§errors: Vec<InterfaceError>

persist(<db>(try_into(error = "…"))) — what HYDRATING a page of this interface refuses with, per database. Never two for one database.

The try_into LEG, and it is the read direction the verb rule names: a page’s rows leave storage for the members’ own wire outputs, and every refusal on that path — the driver’s, the members’ own crossings, and the coherence check between the union and the gather — unifies here. None for a database is the boxed refusal, which absorbs all three through core’s own blanket.

The other three legs stay REFUSED at the front end: from, try_from and into type crossings an interface performs nowhere, and an entry nobody reads is a rule its author believes they declared.

§operand_errors: Vec<InterfaceError>

graphql(input(comparison(<db>(try_into(error = "…"))))) — what CROSSING a wire filter into this database’s predicate refuses with, per database. Never two for one database.

The try_into leg again, and the direction is the same one the verb rule names one axis over: a filter’s operands LEAVE the wire for the types this database stores, so every refusal on that path — each column’s own crossing, and each declared operand converter’s — unifies here. None for a database is the boxed refusal.

Separate from InterfaceModel::errors because they type two crossings that run at different moments: one is a page’s rows leaving storage, the other is a predicate’s operands entering it. A single cell for both would make a caller catch one to learn about the other.

§plural: Option<String>

graphql(plural = "…") — this interface’s plural as a WORD, where the pluraliser’s answer is wrong.

The NAMING TOWER’s middle tier, and the record’s own knob one declaration over: it moves the list FIELD and both page type names together, which is the whole of what the tier buys — one correction of English rather than three readers of it.

None is the derived plural, and a derived plural EQUAL to the singular is legal here where a record refuses it. See InterfaceModel::published_plural.

§connection: Option<String>

graphql(connection(rename = "…")) — what the schema calls a page of this interface.

The tower’s TOP, covering the plural-built word outright and independently of the edge’s.

§edge: Option<String>

graphql(edge(rename = "…")) — what the schema calls one edge of that page.

Implementations§

Source§

impl InterfaceModel

Source

pub fn cursor_name(&self, kind: DatabaseKind) -> Ident

What one database’s CURSOR VALUE is called: <I><Db>Cursor.

Source

pub fn comparison_name(&self, kind: DatabaseKind) -> Ident

What one database’s PREDICATE is called: <I><Db>Comparison.

Source§

impl InterfaceModel

Source

pub fn published_plural(&self) -> String

The word this interface’s LIST FIELD and its two page types are all built from — the declared plural, or the pluraliser’s answer over the interface’s own name.

§The tower is the RECORD’s, applied uniformly — which is D-6
tierthe wordwho writes it
basethe derived plural — Reel ⇒ reels / ReelsConnectionthe pluraliser
over itgraphql(plural = "media")the declaration, ONCE
on topgraphql(connection(rename = "MediaPage"))the declaration, per name

One word moves three names, which is the user’s 一起跟: the field, the connection and the edge all read this, resolved in one place, so a declaration that corrects English once is not asked to correct it again.

§And the DEGENERATE refusal does NOT fire here

A record whose derived plural equals its singular is refused BY NAME, because its two root fields would collide — the single is <camel> and the page would be the same word, and async-graphql builds such a schema silently wrong. That rationale DIED with the get leg: D-4 gives an interface no by-id field, so there is nothing for a page’s name to collide with, and Media ⇒ media is a working list field rather than a silence.

So the refusal is ABSENT rather than relaxed by a flag, and its absence is stated here so a later round does not restore it by symmetry with the record.

Source§

impl InterfaceModel

Source

pub fn error(&self) -> Ident

The refusal type a wrong-variant unwrap answers with — the declared name, else <Interface>UnwrapError.

Source

pub fn fields_name(&self) -> Ident

What the CONTRACT trait is called.

Source

pub fn derivations_name(&self) -> Ident

What the DERIVATIONS trait is called.

Source

pub fn hydration_error(&self, kind: DatabaseKind) -> TokenStream

What HYDRATING a page of this interface in kind refuses with: the declared cell, or the boxed refusal.

The boxed default is what makes the three sources unify without a declaration saying anything: core‘s own blanket absorbs any Error + Send + Sync into it, and the driver’s refusal, the members’ crossings and the coherence check are each one.

Source

pub fn operand_error(&self, kind: DatabaseKind) -> TokenStream

What CROSSING a wire filter into this database’s predicate refuses with: the declared cell, or the boxed refusal.

The boxed default absorbs every column’s crossing without a declaration saying anything, for InterfaceModel::hydration_error’s reason: core’s own blanket takes any Error + Send + Sync into it, and a column’s crossing refusal is one.

Source

pub fn computed_error(&self) -> TokenStream

The type a fallible computed field answers with: the declared one, or the boxed refusal.

Source

pub fn stored(&self) -> impl Iterator<Item = &InterfaceField> + Clone

The fields the members’ ROWS carry — the whole of what the CONTRACT trait is over.

Source

pub fn computed(&self) -> impl Iterator<Item = &InterfaceField> + Clone

The fields a member DERIVES — the whole of what the DERIVATIONS trait is over.

Source

pub fn projected(&self) -> impl Iterator<Item = &InterfaceField> + Clone

The stored fields a UNION ARM can select and the projection row can hold — Self::stored less the collections.

§A collection is stored, promised and equated, and it is not a column of the union’s output

An arm renders SELECT "<the member's name>" AS "<the interface's>", so every column here is one column of one member’s table. A collection is not one on any backend this framework ships: SQLite and MySQL keep every collection in an edge table, PostgreSQL keeps it in a table of its own for the elements its arrays cannot hold, and the choice is the MEMBER’s — so an arm that selected the name would ask a table for a column it may not have, and two arms could disagree about whether it is there at all.

The list is not lost, it arrives one moment later. A page of an interface is two statements — the union, and one gather per member keyed on the addresses it returned — and the gather fetches the member’s WHOLE row through the framework’s own rows, which materializes every collection the row declares. So the client receives the list from the member’s own hydration, which is where a record’s own page receives it too.

So the two lists are two vocabularies rather than one narrowed twice, exactly as RecordModel::ordered_columns and DatabaseBackend::paged_columns are: the CONTRACT promises every stored field, and the PROJECTION carries the ones a union statement can hand back.

Source

pub fn collected(&self) -> impl Iterator<Item = &InterfaceField> + Clone

The stored fields that are COLLECTIONS — Self::stored less Self::projected, and the complement is exact.

What reads it is the per-ARM half of a predicate: a collection has no column in the union’s output to compare, so its conjuncts are rendered against each member’s own edge table rather than once above the union. See SqlInterface::collections.

Source

pub fn stored_at( &self, field: &InterfaceField, kind: DatabaseKind, ) -> TokenStream

The type ONE database keeps one VALUE of this field at — the type a comparison over it is keyed on, and the type a row’s field holds one of.

§A pin names ONE element, and a collection is where that stops being the same sentence

type = "Vec<u64>", persist(sqlite(type = "i64")) says the domain holds a list of u64 and SQLite keeps each of them as an i64. So a WRITTEN pin is already the value’s type at either kind of field, and an unwritten one is not: the domain type of a scalar IS its value, and the domain type of a collection is the list.

So an unpinned collection is asked for its ELEMENT, through the same projection the marker layer resolves a collection’s element with — State<Extracted<Inner>>, the projection layer’s answer to what does this collection hold. Asking the TYPE rather than reading the tokens is what keeps type Marks = Vec<u64> as transparent one level in as it is at the field, which is the rule this emitter keeps everywhere.

Source

pub fn row_at(&self, field: &InterfaceField, kind: DatabaseKind) -> TokenStream

What ONE member’s ROW field holds for this field: the Vec of the stored value where the pin’s word named a collection, and the stored value itself everywhere else.

The other half of Self::stored_at’s split, written beside it so the two readings of one pin are one function apart — see equations, which is their only consumer and the site the split exists for.

Source

pub fn databases(&self) -> Vec<DatabaseKind>

The databases this interface’s row equations are checked at.

The interface’s own persist(…) selection JOINED with every database a field pinned a type at, in DatabaseKind::ALL’s order so an expansion is stable and diffable. Joined rather than taken from one of the two, because both are the declaration saying which databases it is about and neither is a refinement of the other: a field pinning sqlite(type = "u32") has said SQLite as plainly as the block naming it, and an interface whose fields are all short-form has only the block to say it with.

Source

pub fn kind_word(&self, kind: DatabaseKind) -> String

<prefix>_kind__ — the column every arm of this database’s union projects its DISCRIMINANT under, and the Rust field the projection row holds it in.

One name for both faces, which is the discipline the default already keeps: what a decode reads by string and what the struct holds are the same slot, and spelling them differently would be the one place a reader had to hold a mapping.

Source

pub fn source_word(&self, kind: DatabaseKind) -> String

<prefix>_union__ — the name the outer query gives the derived table it selects the union from.

Source

pub fn mints_the_default_words(&self, kind: DatabaseKind) -> bool

Whether this database’s words are the ones the ENGINE already defaults to, which is what lets an emission STATE NOTHING where nothing moved.

The engine defaults both items, so a declaration that named no prefix expands exactly as it did before the knob existed — the posture COLLECTIONS already takes one trait over.

§The comparison is against ingraph’s constant, NOT against this model’s namespace

ingraph::interface::KIND is __ig_kind__ whoever built the model, because the runtime holds one default and it is the framework’s own. So a declaration a DOMAIN FRAMEWORK expanded is never silent here: its words moved relative to what the engine believes, and the emission has to say so. Asking EmissionPrefix::is_default instead would let a __mg model state nothing and then decode __mg_kind__ out of a column its own arm had projected as __ig_kind__ — a failure at run time, where this is none.

Source

pub fn emitted_types(&self) -> Vec<Declared>

Every TYPE this model’s emission declares into the DECLARING SCOPE, in EMISSION ORDER.

The front end refuses a declaration whose emitted names collide, and it asks HERE which those are rather than keeping a list of its own — the argument RecordModel::emitted_types already carries. Each name arrives with what it IS, through the same Role vocabulary the record’s emission speaks, so a collision refusal reads the same whichever derive wrote the type.

Source

pub fn emit(&self) -> TokenStream

The whole expansion: the member face, the contract, the pins discharged at the rows, and the interface’s own projection.

The projection comes LAST because it reads what the equations proved: a row carrying one field per shared column at the pinned type is honest exactly while every member’s own row carries that column at that type, and the equations are what say so. rustc reports in emission order, so a member storing the column at something else is told THAT rather than being told about a decode.

Trait Implementations§

Source§

impl Clone for InterfaceModel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InterfaceModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.