ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
//! The interface's ROOT CITIZENSHIP: `<I>Queries`, the unit a graph's root folds, and the
//! [`Graphql`](../../../ingraph/trait.Graphql.html) binding that seats it.
//!
//! ```text
//! type Query {                  # the graph root's fold, one level up
//!   media(orderBy: […], first: Int, …, where: MediaFilter): MediaConnection!
//!                               # the LIST — MediaQueries::__media_list
//! }
//! ```
//!
//! # It is the RECORD's unit, at an interface
//!
//! The B-27 ruling: *the interface emits an `<I>Queries` unit, same shape as a record's, folded by
//! the SAME MergedObject assembly*. So there is no second mounting mechanism and no second
//! vocabulary — the type is a `Default` unit, its face is one `#[Object]`, and the root that mounts
//! it names `Graphql::Query` exactly as it names a record's.
//!
//! # ONE LEG, and the absent one is a RULING rather than a gap
//!
//! A record's unit carries three legs; this carries the LIST alone. The by-id leg is refused by
//! D-4 — *no interface get leg; the model's own id law decides it* — and the wall is real rather
//! than stylistic: an interface's address is `<I>Id`, a SUM over the members' own ids, and a client
//! sending one would have to say which member it meant, which is the member's own root field
//! spelled twice. A caller learns WHICH concrete get to use from `__typename`, which the wire face
//! beside this pins per arm.
//!
//! The LINEAGE leg is absent for a plainer reason: an interface declares no lineage, having no
//! table for an ancestry to be a path through.
//!
//! # The BINDING is one projection SHORTER than a record's, and that is forced
//!
//! A record's root fields are reached as `<<R as Transformer>::Graphql as Graphql>::Query`. An
//! interface implements no `Transformer`: that trait's supertrait is `Identifiable`, whose `id_ref`
//! hands back a `&Self::Id` — and an interface's id is a sum a member's VALUE holds no instance of,
//! so there is no borrow to return. That is the ruling's *an interface-owned id is unspellable*, met
//! at the one place it decides something.
//!
//! So the interface implements [`Graphql`] DIRECTLY and the root projects `<I as Graphql>::Query`.
//! The SEAT is the same seat; only the road to it is shorter.
//!
//! # What each of the three members binds
//!
//! | member | bound to | why |
//! |---|---|---|
//! | `Input` | `<I>GraphqlInput` | the arguments object, whose own impl names the filter and the order |
//! | `Output` | `<I>GraphqlOutput` | the sum a page's rows hydrate into — the wire face's subject |
//! | `Query` | `<I>Queries`, or `()` | the unit, where this interface can answer a page at all |
//!
//! `GraphqlOutput::Key` binds `()`, and it is an ANSWER rather than a placeholder: that member is
//! *the address a search or knn HIT renders into*, and an interface's engine faces are the fusion
//! seam's future — `<I>Key` exists in Rust and has no wire projection because nothing hands one
//! back yet. The empty product is what the framework's own absent forms are spelled with.
//!
//! # The whole binding rides `projects()`
//!
//! An interface about no SQL database, or one promising no stored column, has no filter, no order
//! and no page — so it has no argument object to bind either, and the honest emission is NONE. A
//! graph that mounts such an interface is `E0277` at the projection carrying [`Graphql`]'s own
//! sentence, which is the same answer a record with no `graphql(…)` block gives.

use quote::quote;

use crate::{
  interface::InterfaceModel,
  model::{DatabaseKind, default_queries_name},
};

#[cfg(test)]
mod tests;
#[cfg(test)]
mod tower_tests;

impl InterfaceModel {
  /// 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
  ///
  /// | tier | the word | who writes it |
  /// |---|---|---|
  /// | base | the derived plural — `Reel` ⇒ `reels` / `ReelsConnection` | the pluraliser |
  /// | over it | `graphql(plural = "media")` | the declaration, ONCE |
  /// | on top | `graphql(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.
  #[must_use]
  pub fn published_plural(&self) -> String {
    self
      .plural
      .clone()
      .unwrap_or_else(|| crate::plural::of(&self.name.to_string()))
  }

  /// The database this interface's ROOT FIELDS are served from, and `None` where it has none.
  ///
  /// The FIRST of its SQL databases, and the choice is the schema's own law read one declaration
  /// over from [`RecordModel::wire_query_row`](crate::model::RecordModel): a client must never see a
  /// field that varies with a deployment's storage choice, so an interface whose members are stored
  /// in two databases answers its root fields from one — the one its declaration named first.
  ///
  /// Gated on [`projects`](Self::projects), which is where the page's whole vocabulary is gated: the
  /// row, the cursor, the predicate and the order are each emitted under it, and a leg naming them
  /// cannot stand where they do not.
  pub(crate) fn wire_query_database(&self) -> Option<DatabaseKind> {
    if !self.projects() {
      return None;
    }
    self.sql_databases().first().copied()
  }

  /// The unit's DECLARATION — outside the binding gate, like every other emitted wire type.
  ///
  /// It has to be: [`Graphql::Query`](../../../ingraph/trait.Graphql.html) is bound in an UNGATED
  /// impl, so a type that existed only where async-graphql does would leave that binding naming
  /// nothing in every other build. The FACE — the `#[Object]` impl — is what rides the gate.
  ///
  /// `Default` because the ROOT is built from one: an emitted `<Root>Query` derives its own over a
  /// tuple of units, which is what makes `Schema::build(<Root>Query::default(), …)` the whole of an
  /// application's construction.
  fn queries_type(&self) -> proc_macro2::TokenStream {
    if self.wire_query_database().is_none() {
      return quote!();
    }
    let vis = &self.vis;
    let interface = &self.name;
    let name = default_queries_name(interface);
    let doc = crate::emit::leading(&format!(
      "The root fields a [`{interface}`] answers — a page of them, across every member the contract \
       declares.\n\nMounted by folding it into a graph's root query; it holds nothing and reads its \
       store through the door the schema was built with. There is no by-id field here and that is a \
       ruling rather than a gap: an interface's address is a SUM over its members' ids, so a row is \
       fetched from the MEMBER's own root and `__typename` is what says which member to ask."
    ));
    quote! {
      #[doc = #doc]
      #[derive(::core::fmt::Debug, ::core::clone::Clone, ::core::marker::Copy, ::core::default::Default)]
      #vis struct #name;
    }
  }

  /// The interface's WIRE BINDING: the two face halves, and [`Graphql`] over them.
  ///
  /// Ungated, as a record's is and for its reason: a root's fold names `Graphql::Query` through a
  /// projection, and a projection into an impl that exists only under a feature is a projection that
  /// fails to resolve everywhere else.
  fn wire_binding(&self) -> proc_macro2::TokenStream {
    if !self.projects() {
      return quote!();
    }
    let interface = &self.name;
    let input = super::default_input_name(interface);
    let output = super::default_output_name(interface);
    let filter = super::default_filter_name(interface);
    let order_by = super::default_order_by_name(interface);
    let face = self.framework(&["transform"], "Graphql");
    let input_face = self.framework(&["transform"], "GraphqlInput");
    let output_face = self.framework(&["transform"], "GraphqlOutput");
    // The UNIT where this interface has root fields, and `()` where it has none — the shape a
    // record's own binding takes at the same member, and the same kind of statement: the empty
    // product is what a fold measures its membership against.
    let queries = match self.wire_query_database() {
      Some(_) => {
        let name = default_queries_name(interface);
        quote!(#name)
      }
      None => quote!(()),
    };
    quote! {
      #[automatically_derived]
      impl #input_face for #input {
        type Filter = #filter;
        type OrderBy = #order_by;
      }

      #[automatically_derived]
      impl #output_face for #output {
        type Key = ();
      }

      #[automatically_derived]
      impl #face for #interface {
        type Input = #input;
        type Output = #output;
        type Query = #queries;
      }
    }
  }

  /// The Rust markers this interface's two SDL page names are spelled through —
  /// `<I>ConnectionName` and `<I>EdgeName` — private to the face's own `const`.
  ///
  /// The record's own arrangement, and for its reasons: the library's
  /// `DefaultConnectionName` renders `<Node>Connection` over the NODE's singular type name, which
  /// the ruled base is not, so there is no declaration this emitter can leave to the library. The
  /// only things that ever name one are the paged leg's return type, in the same const, so they are
  /// not vocabulary a declaring crate can see and need no entry in
  /// [`emitted_types`](Self::emitted_types).
  fn page_names(&self) -> proc_macro2::TokenStream {
    let ag = self.framework(&[], "async_graphql");
    let interface = &self.name;
    // THE TOWER'S BASE, resolved once for both names: the list field's own plural with its initial
    // raised. Asking `published_plural` here rather than re-pluralising is what makes one
    // `plural = "…"` move the field, the page and the edge together.
    let base = crate::emit::raise_initial(&self.published_plural());
    let marker = |declared: Option<&String>, suffix: &str, hook: &str, what: &str| {
      let word = declared.map_or_else(|| format!("{base}{suffix}"), ToOwned::to_owned);
      let name = quote::format_ident!("{interface}{suffix}Name");
      let hook = self.framework(&["graphql"], hook);
      let doc = crate::emit::leading(&format!(
        "What the schema calls {what} of [`{interface}`]s — `{word}`.\n\nThe naming tower's word, \
         resolved in one place: the base is this interface's PLURAL, `graphql(plural = \"…\")` \
         covers it, and `graphql({suffix_word}(rename = \"…\"))` covers that. Tooling that finds a \
         page by the NODE's stem rather than by its fields sees a name it does not recognise, which \
         is the trade the plural base makes once for every declaration that has a page.",
        suffix_word = suffix.to_lowercase(),
      ));
      quote! {
        #[doc = #doc]
        struct #name;

        impl #hook for #name {
          fn type_name<__IngraphNode: #ag::OutputType>() -> ::std::string::String {
            ::std::borrow::ToOwned::to_owned(#word)
          }
        }
      }
    };
    let connection = marker(
      self.connection.as_ref(),
      "Connection",
      "ConnectionNameType",
      "a page",
    );
    let edge = marker(self.edge.as_ref(), "Edge", "EdgeNameType", "one edge");
    quote!(#connection #edge)
  }

  /// **THE LIST LEG** — `<plural>(orderBy:, first:, last:, after:, before:, where:)`, the union over
  /// every declared member, paged and hydrated.
  ///
  /// # The RESULT SET is DECLARATION-DRIVEN, which is D-2's first companion law
  ///
  /// *`media(…)` runs I-2's union over ALL declared members, mounted or not; the mount word only
  /// decides which ROOT FIELDS exist.* Nothing here reads a mount: the union's arms are
  /// `SqlInterface::ARMS`, minted from the declaration's own member list, so a member whose record
  /// nobody mounted still answers this page. What the graph root's `query` word decides is whether
  /// this field is published at all.
  ///
  /// # TWO READS, and the second is a WALL rather than a choice
  ///
  /// A page of an interface is two moments — the union, then one gather per member keyed on the
  /// addresses it returned — and one transaction across both is what the framework's own
  /// `BeginRead` passthrough exists for. **A resolver cannot open one.** `emit::queries`'s module
  /// note measured the wall to its floor and it is the same wall here: async-graphql demands `Send`
  /// of every resolver future, sqlx implements `Acquire<'c>` for a borrowed connection or
  /// transaction at ONE lifetime, and a `Send`-bounded future asks for it at two — so a resolver
  /// holding anything narrower than `&Pool` is *implementation of `sqlx::Acquire` is not general
  /// enough*, at any database, behind any number of helpers. Measured again at this leg, with the
  /// dialect's own `BEGIN` in hand.
  ///
  /// So each call opens its own read. What that costs is stated rather than hidden: a row deleted
  /// BETWEEN the union and the gather is a row the gather cannot find, and the hydration answers
  /// that with its coherence refusal — `HydrationError::Missing`, which crosses as
  /// `UNREADABLE_ROW`. A page that silently lost the row would be a page whose `hasNextPage` is a
  /// lie, which is the judgement that refusal was written on. A caller that needs the two moments
  /// bracketed has the typed door for it — `<I>::find_<db>` and `<I>::hydrate_<db>` both pass a
  /// caller's own `&mut Transaction` through — and that door is Rust-side, where the `Send` bound
  /// is not in the way.
  ///
  /// # The HYDRATION is per member, and the page's ORDER is what puts it back
  ///
  /// The gather answers one member at a time; the page is ordered across all of them. So each
  /// member's addresses are collected WITH the positions they were asked at, and the answers are
  /// scattered back into those slots — the same discipline the hydration itself uses one layer down,
  /// where a row is asked for its own address to be put back in the caller's order.
  fn list_leg(&self, kind: DatabaseKind) -> proc_macro2::TokenStream {
    let interface = &self.name;
    let ag = self.framework(&[], "async_graphql");
    let door = self.framework(&["graphql"], "SqlDoor");
    let orderings = self.framework(&["graphql"], "Orderings");
    let connection = self.framework(&["graphql"], "Connection");
    let page_request = self.framework(&["graphql"], "PageRequest");
    let refused = self.framework(&["graphql"], "refused");
    let refused_filter = self.framework(&["graphql"], "refused_filter");
    let refused_row = self.framework(&["graphql"], "refused_row");
    let try_from_filter = self.framework(&["comparison"], "TryFromFilter");
    let capability = self.framework(&["interface"], "InterfaceKind");
    let page_ty = self.framework(&["query"], "Page");
    let edge_ty = self.framework(&["query"], "Edge");

    let vocabulary = super::default_kind_name(interface);
    let address = super::default_id_name(interface);
    let output = super::default_output_name(interface);
    let row = super::default_row_name(interface, kind);
    let cursor = self.cursor_name(kind);
    let comparison = self.comparison_name(kind);
    let filter = super::default_filter_name(interface);
    let order_by = super::default_order_by_name(interface);
    let (module, item) = kind.backend();
    let backend = self.framework(module, item);
    let hydrate = quote::format_ident!("hydrate_{}", kind.as_str());
    // The EMITTED entry point rather than `InterfaceFind::new` directly, which is the record leg's
    // own arrangement: a declaration has one typed door per database, and a resolver that opened the
    // builder itself would be a second one to keep in step with it.
    let finder = kind.finder();

    let field = crate::emit::lower_initial(&self.published_plural());
    let method = crate::method::wire_method(&quote::format_ident!(
      "{}_list",
      crate::emit::snake(&interface.to_string())
    ));
    let ctx = crate::method::wire_method(&quote::format_ident!("ctx"));
    let (order, first, last, after, before) = (
      crate::method::wire_method(&quote::format_ident!("order_by")),
      crate::method::wire_method(&quote::format_ident!("first")),
      crate::method::wire_method(&quote::format_ident!("last")),
      crate::method::wire_method(&quote::format_ident!("after")),
      crate::method::wire_method(&quote::format_ident!("before")),
    );
    // `where` is a Rust KEYWORD and `Ident::new` takes one, so the base is the plain ident and the
    // `__` prefix is what makes it spellable — the RAW spelling panics inside `format_ident!`, which
    // the record's own leg measured.
    let predicate = crate::method::wire_method(&quote::format_ident!("where"));
    let arity = crate::emit::wide_signature();
    let connection_name = quote::format_ident!("{interface}ConnectionName");
    let edge_name = quote::format_ident!("{interface}EdgeName");

    quote! {
      #[graphql(name = #field)]
      #arity
      async fn #method(
        &self,
        #ctx: &#ag::Context<'_>,
        #[graphql(name = "orderBy")] #order: ::core::option::Option<#orderings<#order_by>>,
        #[graphql(name = "first")] #first: ::core::option::Option<u32>,
        #[graphql(name = "last")] #last: ::core::option::Option<u32>,
        #[graphql(name = "after")] #after: ::core::option::Option<::std::string::String>,
        #[graphql(name = "before")] #before: ::core::option::Option<::std::string::String>,
        // LAST, and that placement is the widening law rather than a preference: the SDL renders
        // arguments in declaration order, so an argument appended leaves every byte before it where
        // it was.
        #[graphql(name = "where")] #predicate: ::core::option::Option<#filter>,
      ) -> #ag::Result<#connection<#output, #cursor, #connection_name, #edge_name>> {
        let __ingraph_door = #ag::Context::data::<#door<#backend>>(#ctx)?;
        // A LOCAL rather than an inline expression, because `InterfaceFind::filter` BORROWS the
        // predicate for the whole walk, so it has to outlive the builder it is handed to.
        let __ingraph_predicate = match #predicate {
          ::core::option::Option::Some(__ingraph_written) => ::core::option::Option::Some(
            <#comparison<#backend> as #try_from_filter<#filter>>::try_from_filter(__ingraph_written)
              .map_err(|__ingraph_refusal| #refused_filter(&__ingraph_refusal))?,
          ),
          ::core::option::Option::None => ::core::option::Option::None,
        };
        let __ingraph_request = <#page_request<#cursor>>::of(
          #first,
          #last,
          ::core::option::Option::as_deref(&#after),
          ::core::option::Option::as_deref(&#before),
        )
        .map_err(|__ingraph_refusal| #refused(&__ingraph_refusal))?;
        // The KEY DEFAULT's one door: an absent argument and `orderBy: []` reach the same empty
        // order, and an interface's own tail — `(…, __ig_kind__, id)` — is what makes the empty one
        // total.
        let __ingraph_terms: ::std::vec::Vec<#order_by> = ::core::iter::Iterator::collect(
          ::core::iter::Iterator::cloned(
            #orderings::terms(&::core::option::Option::unwrap_or_default(#order)),
          ),
        );
        // THE POOL is the surface, and it is FORCED — see this module's note: a resolver future is
        // `Send`-bounded, and sqlx implements `Acquire<'c>` for a borrowed connection at ONE
        // lifetime, so anything narrower than `&Pool` is *implementation of `sqlx::Acquire` is not
        // general enough*. Each call therefore opens its own read, and the gap between the two is
        // what the hydration's coherence refusal reports rather than hides.
        let __ingraph_found = #interface::#finder(#door::pool(__ingraph_door));
        let __ingraph_found = match &__ingraph_predicate {
          ::core::option::Option::Some(__ingraph_narrowing) => {
            __ingraph_found.filter(__ingraph_narrowing)
          }
          ::core::option::Option::None => __ingraph_found,
        };
        let __ingraph_found = __ingraph_found.order(&__ingraph_terms);
        let __ingraph_page: #page_ty<#row, #cursor> = match &__ingraph_request {
          #page_request::Forward { after: __ingraph_at, .. } => {
            let __ingraph_walk = __ingraph_found.first(#page_request::size(&__ingraph_request));
            match __ingraph_at {
              ::core::option::Option::Some(__ingraph_cursor) => {
                __ingraph_walk.after(__ingraph_cursor).fetch().await
              }
              ::core::option::Option::None => __ingraph_walk.fetch().await,
            }
          }
          #page_request::Backward { before: __ingraph_at, .. } => {
            let __ingraph_walk = __ingraph_found.last(#page_request::size(&__ingraph_request));
            match __ingraph_at {
              ::core::option::Option::Some(__ingraph_cursor) => {
                __ingraph_walk.before(__ingraph_cursor).fetch().await
              }
              ::core::option::Option::None => __ingraph_walk.fetch().await,
            }
          }
        }
        .map_err(|__ingraph_refusal| #refused(&__ingraph_refusal))?;

        // THE GATHER, one member at a time, each answer scattered back to the position the PAGE
        // asked for it at — so what a client receives is the statement's order across every member
        // rather than the members' order.
        let __ingraph_rows = #page_ty::edges(&__ingraph_page);
        let mut __ingraph_nodes: ::std::vec::Vec<::core::option::Option<#output>> =
          ::std::vec::Vec::with_capacity(<[_]>::len(__ingraph_rows));
        for _ in 0..<[_]>::len(__ingraph_rows) {
          ::std::vec::Vec::push(&mut __ingraph_nodes, ::core::option::Option::None);
        }
        for __ingraph_kind in <#vocabulary as #capability>::ALL {
          let mut __ingraph_asked: ::std::vec::Vec<#address> = ::std::vec::Vec::new();
          let mut __ingraph_slots: ::std::vec::Vec<usize> = ::std::vec::Vec::new();
          for (__ingraph_at, __ingraph_edge) in
            ::core::iter::Iterator::enumerate(<[_]>::iter(__ingraph_rows))
          {
            let __ingraph_id = #row::id(#edge_ty::node(__ingraph_edge));
            if #address::kind(__ingraph_id) != *__ingraph_kind {
              continue;
            }
            ::std::vec::Vec::push(
              &mut __ingraph_asked,
              ::core::clone::Clone::clone(__ingraph_id),
            );
            ::std::vec::Vec::push(&mut __ingraph_slots, __ingraph_at);
          }
          if ::std::vec::Vec::is_empty(&__ingraph_asked) {
            continue;
          }
          let __ingraph_raised = #interface::#hydrate(
            *__ingraph_kind,
            &__ingraph_asked,
            #door::pool(__ingraph_door),
          )
          .await
          .map_err(|__ingraph_refusal| #refused_row(&__ingraph_refusal))?;
          for (__ingraph_at, __ingraph_node) in ::core::iter::Iterator::zip(
            ::std::vec::Vec::into_iter(__ingraph_slots),
            ::std::vec::Vec::into_iter(__ingraph_raised),
          ) {
            __ingraph_nodes[__ingraph_at] = ::core::option::Option::Some(__ingraph_node);
          }
        }
        #page_ty::into_connection_of(__ingraph_page, __ingraph_nodes)
          .map_err(|__ingraph_refusal| #refused_row(&__ingraph_refusal))
      }
    }
  }

  /// The unit's FACE: `#[Object]` over the one leg, inside the binding gate AND this database's own.
  ///
  /// Both gates, because both halves are named: `#[Object]` is async-graphql's and the engine call
  /// names one dialect's row, its cursor value and its finder.
  fn queries_face(&self) -> proc_macro2::TokenStream {
    let Some(kind) = self.wire_query_database() else {
      return quote!();
    };
    let name = default_queries_name(&self.name);
    let sdl = name.to_string();
    let ag = self.framework(&[], "async_graphql");
    let shelf = crate::emit::vendored(&self.krate, "async_graphql");
    let binding_gate = self.framework(&["gate"], "if_async_graphql");
    let database_gate = self.framework(&["gate"], &kind.gate().to_string());
    let prelude = crate::emit::wire::prelude();
    let names = self.page_names();
    let leg = self.list_leg(kind);
    quote! {
      #binding_gate! {
        #database_gate! {
          const _: () = {
            #prelude

            #names

            #[#ag::Object(crate = #shelf, name = #sdl)]
            impl #name {
              #leg
            }
          };
        }
      }
    }
  }

  /// The unit, the binding that seats it, and the face that answers — this module's whole
  /// contribution to [`InterfaceModel::emit`].
  pub(crate) fn queries(&self) -> proc_macro2::TokenStream {
    let declaration = self.queries_type();
    let binding = self.wire_binding();
    let face = self.queries_face();
    quote! {
      #declaration
      #binding
      #face
    }
  }
}