use heck::ToUpperCamelCase as _;
use quote::{format_ident, quote, quote_spanned};
use super::{ArmModel, MemberModel, SearchModel, SeatModel, SharedBinding, SharedBridge};
use crate::emit::{framework, leading, lower_initial, respan, snake, vendored};
#[cfg(test)]
mod tests;
impl SearchModel {
#[must_use]
pub(super) fn wire(&self) -> proc_macro2::TokenStream {
if !self.mounts() {
return proc_macro2::TokenStream::new();
}
let SearchModel { krate, vis, .. } = self;
let recipe = &self.name;
let unit = self.unit_name();
let face = framework(krate, &["transform"], "Graphql");
let gate = framework(krate, &["gate"], "if_async_graphql");
let prelude = crate::emit::wire::prelude();
let choice = self.ask_input();
let types = self.answer_types();
let faces = self.answer_faces();
let ask = self.ask_fn();
let stretch = self.stretch_fn();
let fields = self.query_fields();
let asked_demand = self.asked_demand();
let unit_sdl = unit.to_string();
let ag = framework(krate, &[], "async_graphql");
let shelf = vendored(krate, "async_graphql");
let unit_doc = leading(&format!(
"The root fields [`{recipe}`] answers — its fused read, in both tiers, as one mountable \
value.\n\nMounted by folding it into a graph's root query; it holds nothing and reaches every \
member's store through the citizens the schema was built with."
));
quote! {
#[doc = #unit_doc]
#[derive(
::core::fmt::Debug,
::core::clone::Clone,
::core::marker::Copy,
::core::default::Default,
)]
#vis struct #unit;
#[automatically_derived]
impl #face for #recipe {
type Input = ();
type Output = ();
type Query = #unit;
}
#gate! {
#choice
#types
#asked_demand
const _: () = {
#prelude
#ask
#stretch
#faces
#[#ag::Object(crate = #shelf, name = #unit_sdl)]
impl #unit {
#fields
}
};
}
}
}
pub(super) fn unit_name(&self) -> syn::Ident {
format_ident!("{}Queries", self.name)
}
fn sighting_name(&self) -> syn::Ident {
format_ident!("{}Sighting", self.name)
}
fn member_sighting_name(&self, member: &MemberModel) -> syn::Ident {
format_ident!(
"{}{}Sighting",
self.name,
member.field.to_string().to_upper_camel_case()
)
}
fn key_match_name(&self) -> syn::Ident {
format_ident!("{}KeyMatch", self.name)
}
fn match_name(&self) -> syn::Ident {
format_ident!("{}Match", self.name)
}
fn stretch_name(&self, keys: bool) -> syn::Ident {
if keys {
format_ident!("{}KeyStretch", self.name)
} else {
format_ident!("{}Stretch", self.name)
}
}
fn stretch_field_name(&self, keys: bool) -> String {
format!("{}Stretch", self.field_name(keys))
}
fn stretch_fn_name(&self) -> syn::Ident {
format_ident!("__ingraph_{}_stretch", snake(&self.name.to_string()))
}
fn ask_name(&self) -> syn::Ident {
format_ident!("__ingraph_{}_ask", snake(&self.name.to_string()))
}
fn field_name(&self, keys: bool) -> String {
let subject = lower_initial(&self.name.to_string());
if keys {
format!("{subject}Keys")
} else {
subject
}
}
fn ask_input_name(&self) -> syn::Ident {
format_ident!("{}AskInput", self.name)
}
fn seat_variant(seat: &SeatModel) -> syn::Ident {
format_ident!("{}", seat.name.to_string().to_upper_camel_case())
}
fn seat_word(seat: &SeatModel) -> String {
crate::name::RustSafeName::from_ident(&seat.name)
.external()
.to_owned()
}
fn broadcast_ty(&self) -> proc_macro2::TokenStream {
if self.chooses() {
let choice = self.ask_input_name();
return quote!(#choice);
}
let seat = &self.seats[0].ty;
quote!(#seat)
}
fn broadcast_word(&self) -> String {
if self.chooses() {
return ASK.to_owned();
}
Self::seat_word(&self.seats[0])
}
fn broadcast_binding(&self) -> syn::Ident {
crate::method::wire_method(&format_ident!("{}", snake(&self.broadcast_word())))
}
fn engine(&self, member: &MemberModel) -> proc_macro2::TokenStream {
let named = framework(&self.krate, &["graphql"], "FusedEngine");
let ty = &member.ty;
quote!(<#ty as #named>::Engine)
}
fn read_at(&self, member: &MemberModel) -> proc_macro2::TokenStream {
let read = framework(&self.krate, &["retrieve"], "AsyncFusedRead");
let engine = self.engine(member);
quote!(#read<#engine>)
}
fn root(&self) -> proc_macro2::TokenStream {
let first = &self.members[0];
let ty = &first.ty;
let read = self.read_at(first);
quote!(<#ty as #read>::Root)
}
fn address(&self) -> proc_macro2::TokenStream {
let wire = framework(&self.krate, &["graphql"], "WireRoot");
let root = self.root();
quote!(<#root as #wire>::Address)
}
fn entity(&self) -> proc_macro2::TokenStream {
let wire = framework(&self.krate, &["graphql"], "WireRoot");
let root = self.root();
quote!(<#root as #wire>::Entity)
}
fn evidence_of(&self, member: &MemberModel) -> proc_macro2::TokenStream {
let ty = &member.ty;
let read = self.read_at(member);
quote!(<#ty as #read>::Evidence)
}
fn ask_input(&self) -> proc_macro2::TokenStream {
if !self.chooses() {
return proc_macro2::TokenStream::new();
}
let krate = &self.krate;
let vis = &self.vis;
let ag = framework(krate, &[], "async_graphql");
let recipe = &self.name;
let name = self.ask_input_name();
let sdl = name.to_string();
let declared = self.seats.iter().map(|seat| {
let variant = Self::seat_variant(seat);
let ty = &seat.ty;
let doc = leading(&format!(
"Asking [`{recipe}`] at its `{seat}` seat — the members whose arms bought `{seat}` answer, \
and every other member of this recipe is absent from the request.",
seat = seat.name,
));
quote! {
#[doc = #doc]
#variant(#ty)
}
});
let entries = self.seats.iter().map(|seat| {
let ty = &seat.ty;
let word = Self::seat_word(seat);
quote! {
__ingraph_fields.insert(
::std::string::String::from(#word),
#ag::registry::MetaInputValue {
name: ::std::string::String::from(#word),
description: ::core::option::Option::None,
ty: <::core::option::Option<#ty> as #ag::InputType>::create_type_info(
__ingraph_registry,
),
deprecation: #ag::registry::Deprecation::NoDeprecated,
default_value: ::core::option::Option::None,
visible: ::core::option::Option::None,
inaccessible: false,
tags: ::std::vec::Vec::new(),
is_secret: false,
directive_invocations: ::std::vec::Vec::new(),
},
);
}
});
let reads = self.seats.iter().map(|seat| {
let variant = Self::seat_variant(seat);
let word = Self::seat_word(seat);
quote! {
if #ag::indexmap::IndexMap::contains_key(&__ingraph_object, #word)
&& __ingraph_object.len() == 1
{
let __ingraph_filled = #ag::InputType::parse(
#ag::indexmap::IndexMap::swap_remove(&mut __ingraph_object, #word),
)
.map_err(#ag::InputValueError::propagate)?;
return ::core::result::Result::Ok(Self::#variant(__ingraph_filled));
}
}
});
let writes = self.seats.iter().map(|seat| {
let variant = Self::seat_variant(seat);
let word = Self::seat_word(seat);
quote! {
Self::#variant(__ingraph_filled) => {
__ingraph_map.insert(
#ag::Name::new(#word),
#ag::InputType::to_value(__ingraph_filled),
);
}
}
});
let doc = leading(&format!(
"HOW a request asks [`{recipe}`] — one field per declared seat, and a request fills exactly \
one.\n\nThe seats are MODES rather than parts of one question: the members whose arms bought \
the filled seat answer the request, and the rest are structurally absent from it. A value \
that rides WITH a question — a language, a locale — is a field of a seat's own TYPE and never \
a seat beside it, because filling one seat means not filling the others."
));
quote! {
#[doc = #doc]
#vis enum #name {
#(#declared,)*
}
const _: () = {
#[automatically_derived]
impl #ag::InputType for #name {
type RawValueType = Self;
#[inline]
fn type_name() -> ::std::borrow::Cow<'static, ::core::primitive::str> {
::std::borrow::Cow::Borrowed(#sdl)
}
fn create_type_info(
__ingraph_registry: &mut #ag::registry::Registry,
) -> ::std::string::String {
__ingraph_registry.create_input_type::<Self, _>(
#ag::registry::MetaTypeId::InputObject,
|__ingraph_registry| #ag::registry::MetaType::InputObject {
name: ::std::string::String::from(#sdl),
description: ::core::option::Option::None,
input_fields: {
let mut __ingraph_fields = #ag::indexmap::IndexMap::new();
#(#entries)*
__ingraph_fields
},
visible: ::core::option::Option::None,
inaccessible: false,
tags: ::std::vec::Vec::new(),
rust_typename: ::core::option::Option::Some(::core::any::type_name::<Self>()),
oneof: true,
directive_invocations: ::std::vec::Vec::new(),
},
)
}
fn parse(
__ingraph_value: ::core::option::Option<#ag::Value>,
) -> #ag::InputValueResult<Self> {
if let ::core::option::Option::Some(#ag::Value::Object(mut __ingraph_object)) =
__ingraph_value
{
#(#reads)*
return ::core::result::Result::Err(#ag::InputValueError::expected_type(
#ag::Value::Object(__ingraph_object),
));
}
::core::result::Result::Err(#ag::InputValueError::expected_type(
::core::option::Option::unwrap_or_default(__ingraph_value),
))
}
fn to_value(&self) -> #ag::Value {
let mut __ingraph_map = #ag::indexmap::IndexMap::new();
match self {
#(#writes)*
}
#ag::Value::Object(__ingraph_map)
}
#[inline]
fn as_raw_value(&self) -> ::core::option::Option<&Self::RawValueType> {
::core::option::Option::Some(self)
}
}
#[automatically_derived]
impl #ag::InputObjectType for #name {}
#[automatically_derived]
impl #ag::OneofObjectType for #name {}
};
}
}
fn answer_types(&self) -> proc_macro2::TokenStream {
let vis = &self.vis;
let sighting = self.sighting_name();
let key_match = self.key_match_name();
let hydrated_match = self.match_name();
let key_stretch = self.stretch_name(true);
let hydrated_stretch = self.stretch_name(false);
let root = self.address();
let entity = self.entity();
let recipe = &self.name;
let members: Vec<syn::Ident> = self
.members
.iter()
.map(|member| self.member_sighting_name(member))
.collect();
let variants: Vec<syn::Ident> = self.members.iter().map(variant).collect();
let sightings = self.members.iter().zip(&members).map(|(member, name)| {
let score = self.evidence_of(member);
let field = &member.field;
let doc = leading(&format!(
"What [`{recipe}`]'s `{field}` member said about a fused root: its OWN evidence, the rank it \
gave the root in its own stream, and the term that rank added to the fused score.\n\nThe \
evidence is the member's whole provenance and this type opens none of it — a member that \
fuses several routes of its own hands over its own evidence enum, all the way down."
));
quote! {
#[doc = #doc]
#[derive(::core::fmt::Debug, ::core::clone::Clone, ::core::cmp::PartialEq)]
#vis struct #name {
seen: #score,
ordinal: ::core::primitive::u64,
contribution: ::core::primitive::f64,
}
#[automatically_derived]
impl #name {
#[doc = " One entry, taken as the fold computed it."]
#[must_use]
#[inline]
#vis const fn new(
seen: #score,
ordinal: ::core::primitive::u64,
contribution: ::core::primitive::f64,
) -> Self {
Self { seen, ordinal, contribution }
}
#[doc = " What this member itself saw, in its own currency."]
#[must_use]
#[inline]
#vis const fn seen_ref(&self) -> &#score {
&self.seen
}
#[doc = " The rank this member gave the root, in its OWN stream."]
#[must_use]
#[inline]
#vis const fn ordinal(&self) -> ::core::primitive::u64 {
self.ordinal
}
#[doc = " The weighted term this sighting added to the fused score."]
#[must_use]
#[inline]
#vis const fn contribution(&self) -> ::core::primitive::f64 {
self.contribution
}
}
}
});
let union_doc = leading(&format!(
"WHICH of [`{recipe}`]'s members put a root where it is — one arm per member, each carrying \
that member's own sighting.\n\nA SUM and not a product: a sighting IS one member's, and each \
member scores in its own currency, which crosses as itself. A product with one nullable row \
per member would publish a shape where all of them could be set and none of them had to be."
));
let key_match_doc = leading(&format!(
"One fused result of [`{recipe}`], addressed — the root, the fused score, and every member \
that put it there."
));
let hydrated_match_doc = leading(&format!(
"One fused result of [`{recipe}`], HYDRATED — the row the address points at, beside the same \
score and the same provenance.\n\nThe twin of the keys tier and in the same order: a row that \
has gone is dropped rather than shifting the rows after it, so the two answers read side by \
side."
));
let key_stretch_doc = leading(&format!(
"One STRETCH of a ranking [`{recipe}`] computed once and this deployment is holding: the \
addresses of this stretch, and the page token that claims the next one.\n\nThe rows are \
exact within the snapshot — one ranking taken at one moment, so a document indexed between \
two stretches neither appears twice nor pushes a row off the end. The page token is opaque, \
session-ephemeral, and refused by name once its answer is gone."
));
let hydrated_stretch_doc = leading(&format!(
"One STRETCH of a ranking [`{recipe}`] computed once, HYDRATED — the keys tier's own \
stretch with each address resolved, in the same order and with the same provenance.\n\nThe \
snapshot holds addresses and scores only; hydration happens per stretch, which is what \
keeps a kept ranking's memory a function of its depth rather than of a row's width."
));
quote! {
#(#sightings)*
#[doc = #union_doc]
#[derive(::core::fmt::Debug, ::core::clone::Clone, ::core::cmp::PartialEq)]
#vis enum #sighting {
#(#variants(#members),)*
}
#[doc = #key_match_doc]
#[derive(::core::fmt::Debug, ::core::clone::Clone)]
#vis struct #key_match {
key: #root,
score: ::core::primitive::f64,
evidence: ::std::vec::Vec<#sighting>,
}
#[automatically_derived]
impl #key_match {
#[doc = " One row, assembled out of the fold's own answer."]
#[must_use]
#[inline]
#vis const fn new(
key: #root,
score: ::core::primitive::f64,
evidence: ::std::vec::Vec<#sighting>,
) -> Self {
Self { key, score, evidence }
}
#[doc = " The address this row is about."]
#[must_use]
#[inline]
#vis const fn key_ref(&self) -> &#root {
&self.key
}
#[doc = " The FUSED score — comparable against the other rows of this answer and nothing else."]
#[must_use]
#[inline]
#vis const fn score(&self) -> ::core::primitive::f64 {
self.score
}
#[doc = " Every member that saw this root, biggest mover first."]
#[must_use]
#[inline]
#vis fn evidence(&self) -> &[#sighting] {
&self.evidence
}
#[doc = " All three, none cloned — for a reader that takes the row apart."]
#[must_use]
#[inline]
#vis fn into_components(
self,
) -> (#root, ::core::primitive::f64, ::std::vec::Vec<#sighting>) {
(self.key, self.score, self.evidence)
}
}
#[doc = #hydrated_match_doc]
#vis struct #hydrated_match {
entity: #entity,
score: ::core::primitive::f64,
evidence: ::std::vec::Vec<#sighting>,
}
#[automatically_derived]
impl #hydrated_match {
#[doc = " One row, the address already resolved."]
#[must_use]
#[inline]
#vis const fn new(
entity: #entity,
score: ::core::primitive::f64,
evidence: ::std::vec::Vec<#sighting>,
) -> Self {
Self { entity, score, evidence }
}
#[doc = " The row this result is about."]
#[must_use]
#[inline]
#vis const fn entity_ref(&self) -> &#entity {
&self.entity
}
#[doc = " The FUSED score — the keys tier's own number, unchanged by hydration."]
#[must_use]
#[inline]
#vis const fn score(&self) -> ::core::primitive::f64 {
self.score
}
#[doc = " Every member that saw this root, biggest mover first."]
#[must_use]
#[inline]
#vis fn evidence(&self) -> &[#sighting] {
&self.evidence
}
}
#[doc = #key_stretch_doc]
#[derive(::core::fmt::Debug, ::core::clone::Clone)]
#vis struct #key_stretch {
matches: ::std::vec::Vec<#key_match>,
next_page_token: ::core::option::Option<::std::string::String>,
}
#[automatically_derived]
impl #key_stretch {
#[doc = " One stretch of a kept ranking, and the claim on the next."]
#[must_use]
#[inline]
#vis const fn new(
matches: ::std::vec::Vec<#key_match>,
next_page_token: ::core::option::Option<::std::string::String>,
) -> Self {
Self { matches, next_page_token }
}
#[doc = " The rows of this stretch, in the ranking's own order."]
#[must_use]
#[inline]
#vis fn matches(&self) -> &[#key_match] {
&self.matches
}
#[doc = " The page token that claims the next stretch, or `None` at the end of the ranking."]
#[must_use]
#[inline]
#vis fn next_page_token(&self) -> ::core::option::Option<&::core::primitive::str> {
::core::option::Option::as_deref(&self.next_page_token)
}
}
#[doc = #hydrated_stretch_doc]
#vis struct #hydrated_stretch {
matches: ::std::vec::Vec<#hydrated_match>,
next_page_token: ::core::option::Option<::std::string::String>,
}
#[automatically_derived]
impl #hydrated_stretch {
#[doc = " One stretch of a kept ranking, hydrated, and the claim on the next."]
#[must_use]
#[inline]
#vis const fn new(
matches: ::std::vec::Vec<#hydrated_match>,
next_page_token: ::core::option::Option<::std::string::String>,
) -> Self {
Self { matches, next_page_token }
}
#[doc = " The rows of this stretch, in the keys tier's own order."]
#[must_use]
#[inline]
#vis fn matches(&self) -> &[#hydrated_match] {
&self.matches
}
#[doc = " The page token that claims the next stretch, or `None` at the end of the ranking."]
#[must_use]
#[inline]
#vis fn next_page_token(&self) -> ::core::option::Option<&::core::primitive::str> {
::core::option::Option::as_deref(&self.next_page_token)
}
}
}
}
fn answer_faces(&self) -> proc_macro2::TokenStream {
let krate = &self.krate;
let ag = framework(krate, &[], "async_graphql");
let shelf = vendored(krate, "async_graphql");
let wire_score = framework(krate, &["graphql"], "WireScore");
let sighting = self.sighting_name();
let key_match = self.key_match_name();
let hydrated_match = self.match_name();
let key_stretch = self.stretch_name(true);
let hydrated_stretch = self.stretch_name(false);
let key_stretch_sdl = key_stretch.to_string();
let hydrated_stretch_sdl = hydrated_stretch.to_string();
let (matches_method, next_page_token_method) = (
crate::method::wire_method(&format_ident!("matches")),
crate::method::wire_method(&format_ident!("next_page_token")),
);
let root = self.address();
let entity = self.entity();
let members: Vec<syn::Ident> = self
.members
.iter()
.map(|member| self.member_sighting_name(member))
.collect();
let variants: Vec<syn::Ident> = self.members.iter().map(variant).collect();
let union_sdl = sighting.to_string();
let member_faces = self.members.iter().zip(&members).map(|(member, name)| {
let score = self.evidence_of(member);
let sdl = name.to_string();
let field = &member.field;
let doc = format!(" What the `{field}` member said about this root.");
let (score_method, ordinal, contribution) = (
crate::method::wire_method(&format_ident!("score")),
crate::method::wire_method(&format_ident!("ordinal")),
crate::method::wire_method(&format_ident!("contribution")),
);
quote! {
#[doc = #doc]
#[#ag::Object(crate = #shelf, name = #sdl)]
impl #name {
#[graphql(name = "score")]
async fn #score_method<'__ingraph_row>(
&'__ingraph_row self,
) -> <#score as #wire_score>::Wire<'__ingraph_row> {
<#score as #wire_score>::wire_score(#name::seen_ref(self))
}
#[graphql(name = "ordinal")]
async fn #ordinal(&self) -> ::core::primitive::u64 {
#name::ordinal(self)
}
#[graphql(name = "contribution")]
async fn #contribution(&self) -> ::core::primitive::f64 {
#name::contribution(self)
}
}
}
});
let (node_method, score_method, evidence_method) = (
crate::method::wire_method(&format_ident!("node")),
crate::method::wire_method(&format_ident!("score")),
crate::method::wire_method(&format_ident!("evidence")),
);
let key_match_sdl = key_match.to_string();
let hydrated_match_sdl = hydrated_match.to_string();
quote! {
#(#member_faces)*
#[automatically_derived]
impl #ag::resolver_utils::ContainerType for #sighting {
async fn resolve_field(
&self,
_ctx: &#ag::Context<'_>,
) -> #ag::ServerResult<::core::option::Option<#ag::Value>> {
::core::result::Result::Ok(::core::option::Option::None)
}
fn collect_all_fields<'__ingraph_seen>(
&'__ingraph_seen self,
__ingraph_ctx: &#ag::ContextSelectionSet<'__ingraph_seen>,
__ingraph_fields: &mut #ag::resolver_utils::Fields<'__ingraph_seen>,
) -> #ag::ServerResult<()> {
match self {
#(Self::#variants(__ingraph_arm) => #ag::resolver_utils::ContainerType::collect_all_fields(
__ingraph_arm,
__ingraph_ctx,
__ingraph_fields,
),)*
}
}
}
#[automatically_derived]
impl #ag::OutputType for #sighting {
fn type_name() -> ::std::borrow::Cow<'static, ::core::primitive::str> {
::std::borrow::Cow::Borrowed(#union_sdl)
}
fn introspection_type_name(&self) -> ::std::borrow::Cow<'static, ::core::primitive::str> {
match self {
#(Self::#variants(_) => <#members as #ag::OutputType>::type_name(),)*
}
}
fn create_type_info(
__ingraph_registry: &mut #ag::registry::Registry,
) -> ::std::string::String {
__ingraph_registry.create_output_type::<Self, _>(
#ag::registry::MetaTypeId::Union,
|__ingraph_registry| {
#(<#members as #ag::OutputType>::create_type_info(__ingraph_registry);)*
#ag::registry::MetaType::Union {
name: ::std::string::String::from(#union_sdl),
description: ::core::option::Option::None,
possible_types: {
let mut __ingraph_arms = #ag::indexmap::IndexSet::new();
#(__ingraph_arms.insert(::std::borrow::Cow::into_owned(
<#members as #ag::OutputType>::type_name(),
));)*
__ingraph_arms
},
visible: ::core::option::Option::None,
inaccessible: false,
tags: ::std::vec::Vec::new(),
rust_typename: ::core::option::Option::Some(::core::any::type_name::<Self>()),
directive_invocations: ::std::vec::Vec::new(),
}
},
)
}
async fn resolve(
&self,
__ingraph_ctx: &#ag::ContextSelectionSet<'_>,
_field: &#ag::Positioned<#ag::parser::types::Field>,
) -> #ag::ServerResult<#ag::Value> {
#ag::resolver_utils::resolve_container(__ingraph_ctx, self).await
}
}
#[automatically_derived]
impl #ag::UnionType for #sighting {}
#[doc = " One fused result: the address, the fused score, and every member that put it there."]
#[#ag::Object(crate = #shelf, name = #key_match_sdl)]
impl #key_match {
#[graphql(name = "node")]
async fn #node_method(&self) -> &#root {
#key_match::key_ref(self)
}
#[graphql(name = "score")]
async fn #score_method(&self) -> ::core::primitive::f64 {
#key_match::score(self)
}
#[graphql(name = "evidence")]
async fn #evidence_method(&self) -> &[#sighting] {
#key_match::evidence(self)
}
}
#[doc = " One fused result, hydrated: the row, the same score, and the same provenance."]
#[#ag::Object(crate = #shelf, name = #hydrated_match_sdl)]
impl #hydrated_match {
#[graphql(name = "node")]
async fn #node_method(&self) -> &#entity {
#hydrated_match::entity_ref(self)
}
#[graphql(name = "score")]
async fn #score_method(&self) -> ::core::primitive::f64 {
#hydrated_match::score(self)
}
#[graphql(name = "evidence")]
async fn #evidence_method(&self) -> &[#sighting] {
#hydrated_match::evidence(self)
}
}
#[doc = " One stretch of a kept ranking: its rows, and the claim on the next stretch."]
#[#ag::Object(crate = #shelf, name = #key_stretch_sdl)]
impl #key_stretch {
#[graphql(name = "matches")]
async fn #matches_method(&self) -> &[#key_match] {
#key_stretch::matches(self)
}
#[graphql(name = "nextPageToken")]
async fn #next_page_token_method(&self) -> ::core::option::Option<&::core::primitive::str> {
#key_stretch::next_page_token(self)
}
}
#[doc = " One stretch of a kept ranking, hydrated: its rows, and the claim on the next."]
#[#ag::Object(crate = #shelf, name = #hydrated_stretch_sdl)]
impl #hydrated_stretch {
#[graphql(name = "matches")]
async fn #matches_method(&self) -> &[#hydrated_match] {
#hydrated_stretch::matches(self)
}
#[graphql(name = "nextPageToken")]
async fn #next_page_token_method(&self) -> ::core::option::Option<&::core::primitive::str> {
#hydrated_stretch::next_page_token(self)
}
}
}
}
fn asked_tower(&self) -> Option<&syn::Type> {
use quote::ToTokens as _;
let mut bound = self
.members
.iter()
.flat_map(|member| member.arms.iter())
.filter(|arm| arm.shared.is_some())
.map(|arm| &arm.tower);
let first = bound.next()?;
let spelling = first.to_token_stream().to_string();
bound
.all(|tower| tower.to_token_stream().to_string() == spelling)
.then_some(first)
}
fn asked_ty(&self) -> Option<proc_macro2::TokenStream> {
use syn::spanned::Spanned as _;
let tower = self.asked_tower()?;
let at = tower.span();
let declared = respan(framework(&self.krate, &["retrieve"], "DeclaredTower"), at);
Some(quote_spanned!(at=> <#tower as #declared>::SearchOptions))
}
fn asked_parameter(&self) -> Option<proc_macro2::TokenStream> {
let ty = self.asked_ty()?;
Some(quote! {
__ingraph_request: ::core::option::Option<#ty>,
})
}
fn asked_argument(&self, binding: &syn::Ident) -> Option<proc_macro2::TokenStream> {
let ty = self.asked_ty()?;
Some(quote! {
#[graphql(name = "options")] #binding: ::core::option::Option<#ty>,
})
}
fn asked_demand(&self) -> Option<proc_macro2::TokenStream> {
use syn::spanned::Spanned as _;
let ty = self.asked_ty()?;
let at = self.asked_tower()?.span();
let face = respan(
framework(&self.krate, &["graphql"], "SearchOptionsFace"),
at,
);
Some(quote_spanned! {at=>
const _: fn() = || {
fn __ingraph_asks<__IgAsked: #face + ?::core::marker::Sized>() {}
__ingraph_asks::<#ty>();
};
})
}
fn producer<'a>(&self, member: &'a MemberModel, seat: &syn::Ident) -> Producer<'a> {
let mut bought = member
.arms
.iter()
.filter_map(|arm| arm.shared.as_ref().map(|shared| (arm, shared)))
.peekable();
if bought.peek().is_none() {
return Producer::Broadcast;
}
bought
.find(|(_, shared)| shared.seat == *seat)
.map_or(Producer::Elsewhere, |(arm, shared)| {
Producer::Arm(arm, shared)
})
}
fn walked(&self, arm: &ArmModel, shared: &SharedBinding) -> proc_macro2::TokenStream {
use syn::spanned::Spanned as _;
let krate = &self.krate;
let at = arm.tower.span();
let ag = framework(krate, &[], "async_graphql");
let tower = &arm.tower;
let tower_face = respan(framework(krate, &["retrieve"], "SearchTower"), at);
let assembled = respan(framework(krate, &["retrieve"], "AssembledTower"), at);
let installed = respan(framework(krate, &["graphql"], "installed_road"), at);
let within = respan(framework(krate, &["retrieve"], "walk_within"), at);
let asked = self.bridged(arm, shared);
let (borrowed_request, handed_request) = if self.asked_tower().is_some() {
(
quote_spanned!(at=> ::core::option::Option::as_ref(&__ingraph_request)),
quote_spanned!(at=> ::core::clone::Clone::clone(&__ingraph_request)),
)
} else {
(
quote_spanned!(at=> ::core::option::Option::None),
quote_spanned!(at=> ::core::option::Option::None),
)
};
quote_spanned! {at=>
let (mut __ingraph_road, __ingraph_knobs, __ingraph_wall) =
#installed::<#tower>(__ingraph_ctx, __ingraph_word)?;
#[allow(clippy::clone_on_copy, clippy::useless_conversion)]
let __ingraph_asked: <#tower as #tower_face>::Question = #asked;
let __ingraph_walked = #within(
__ingraph_wall,
<#tower as #assembled>::asked_budget(#borrowed_request),
::core::any::type_name::<#tower>(),
<#tower as #assembled>::run(
&mut __ingraph_road,
__ingraph_asked,
__ingraph_knobs,
#handed_request,
),
).await;
let __ingraph_answered = match __ingraph_walked {
::core::result::Result::Ok(::core::result::Result::Ok(__ingraph_answered)) => {
__ingraph_answered
}
::core::result::Result::Ok(::core::result::Result::Err(__ingraph_refusal)) => {
return ::core::result::Result::Err(#ag::Error::new(
::std::string::ToString::to_string(&__ingraph_refusal),
));
}
::core::result::Result::Err(__ingraph_spent) => {
return ::core::result::Result::Err(#ag::Error::new(
::std::string::ToString::to_string(&__ingraph_spent),
));
}
};
}
}
fn bridged(&self, arm: &ArmModel, shared: &SharedBinding) -> proc_macro2::TokenStream {
use syn::spanned::Spanned as _;
let krate = &self.krate;
let at = arm.tower.span();
let ag = framework(krate, &[], "async_graphql");
let tower = &arm.tower;
let tower_face = respan(framework(krate, &["retrieve"], "SearchTower"), at);
let copied = quote_spanned!(at=> ::core::clone::Clone::clone(__ingraph_broadcast));
match &shared.bridge {
SharedBridge::Total => quote_spanned! {at=>
<<#tower as #tower_face>::Question as ::core::convert::From<_>>::from(#copied)
},
SharedBridge::Fallible => quote_spanned! {at=>
match <<#tower as #tower_face>::Question as ::core::convert::TryFrom<_>>::try_from(#copied) {
::core::result::Result::Ok(__ingraph_asked) => __ingraph_asked,
::core::result::Result::Err(__ingraph_refusal) => {
return ::core::result::Result::Err(#ag::Error::new(
::std::string::ToString::to_string(&__ingraph_refusal),
));
}
}
},
SharedBridge::Hook(path) => quote_spanned!(at=> #path(__ingraph_broadcast)),
SharedBridge::FallibleHook(path) => quote_spanned! {at=>
match #path(__ingraph_broadcast) {
::core::result::Result::Ok(__ingraph_asked) => __ingraph_asked,
::core::result::Result::Err(__ingraph_refusal) => {
return ::core::result::Result::Err(#ag::Error::new(
::std::string::ToString::to_string(&__ingraph_refusal),
));
}
}
},
}
}
fn crossings(&self) -> proc_macro2::TokenStream {
let question_package = self.question_name();
if !self.chooses() {
let asked = self.seat_crossings(&self.seats[0]);
return quote! {
let __ingraph_question = #question_package::new();
#(#asked)*
};
}
let choice = self.ask_input_name();
let arms = self.seats.iter().map(|seat| {
let variant = Self::seat_variant(seat);
let asked = self.seat_crossings(seat);
quote! {
#choice::#variant(__ingraph_broadcast) => {
#(#asked)*
__ingraph_question
}
}
});
quote! {
let __ingraph_question = #question_package::new();
let __ingraph_question = match __ingraph_broadcast {
#(#arms)*
};
}
}
fn seat_crossings(&self, seat: &SeatModel) -> Vec<proc_macro2::TokenStream> {
let krate = &self.krate;
let ag = framework(krate, &[], "async_graphql");
let crossing = framework(krate, &["retrieve"], "TrySharedQuestion");
let fusable = framework(krate, &["retrieve"], "Fusable");
let question_package = self.question_name();
let seat_ty = &seat.ty;
let seat_marker = self.seat_marker_name(&seat.name);
self
.members
.iter()
.filter_map(|member| {
let field = &member.field;
let ty = &member.ty;
let with = format_ident!("with_{field}");
let (walked, broadcast, from) = match self.producer(member, &seat.name) {
Producer::Arm(arm, shared) => {
let tower = &arm.tower;
let tower_face = framework(krate, &["retrieve"], "SearchTower");
(
self.walked(arm, shared),
quote!(<#tower as #tower_face>::Answer),
quote!(&__ingraph_answered),
)
}
Producer::Broadcast => (
proc_macro2::TokenStream::new(),
quote!(#seat_ty),
quote!(__ingraph_broadcast),
),
Producer::Elsewhere => return None,
};
Some(quote! {
#walked
let __ingraph_question = match <
<#ty as #fusable>::Question as #crossing<#seat_marker, #broadcast>
>::try_from_shared(#from) {
::core::result::Result::Ok(::core::option::Option::Some(__ingraph_asked)) => {
#question_package::#with(__ingraph_question, __ingraph_asked)
}
::core::result::Result::Ok(::core::option::Option::None) => __ingraph_question,
::core::result::Result::Err(__ingraph_refusal) => {
return ::core::result::Result::Err(#ag::Error::new(
::std::string::ToString::to_string(&__ingraph_refusal),
));
}
};
})
})
.collect()
}
fn ask_fn(&self) -> proc_macro2::TokenStream {
let krate = &self.krate;
let ag = framework(krate, &[], "async_graphql");
let citizen = framework(krate, &["graphql"], "FusedCitizen");
let fusable = framework(krate, &["retrieve"], "Fusable");
let route = framework(krate, &["retrieve"], "Route");
let depth_law = framework(krate, &["retrieve"], "route_depth");
let flavour = framework(krate, &["retrieve"], "FusionOptions");
let fusion = framework(krate, &["retrieve"], "Fusion");
let rooted = framework(krate, &["retrieve"], "Rooted");
let weighted = framework(krate, &["retrieve"], "fuse_weighted");
let join = framework(krate, &["retrieve"], self.dedup.join());
let fused = framework(krate, &["retrieve"], "Fused");
let fused_score = framework(krate, &["retrieve"], "FusedScore");
let sighting_of = framework(krate, &["retrieve"], "Sighting");
let ask = self.ask_name();
let sighting = self.sighting_name();
let evidence = self.evidence_name();
let question_package = self.question_name();
let options_package = self.options_name();
let root = self.root();
let broadcast_ty = self.broadcast_ty();
let asked = self.crossings();
let edges: Vec<proc_macro2::TokenStream> = self
.members
.iter()
.map(|member| {
let field = &member.field;
let ty = &member.ty;
let with = format_ident!("with_{field}");
let mut built = quote!(#route::<<#ty as #fusable>::Options>::new());
if let Some(weight) = member.weight {
built = quote!(#route::with_weight(#built, #weight));
}
if let Some(depth) = member.depth {
let depth = depth.get() as usize;
built = quote! {
#route::with_depth(
#built,
match ::core::num::NonZeroUsize::new(#depth) {
::core::option::Option::Some(__ingraph_deep) => __ingraph_deep,
::core::option::Option::None => ::core::num::NonZeroUsize::MIN,
},
)
};
}
quote! {
let __ingraph_options = #options_package::#with(__ingraph_options, #built);
}
})
.collect();
let reads = self.members.iter().map(|member| {
let field = &member.field;
let ty = &member.ty;
let variant = variant(member);
let engine = self.engine(member);
let edge = self.member_edge(member);
quote! {
{
#edge
if let (true, ::core::option::Option::Some(__ingraph_asked)) =
(__ingraph_enabled, #question_package::#field(question))
{
let __ingraph_ranked = <#ty as #citizen<#engine>>::ranked(
__ingraph_ctx,
::core::option::Option::and_then(__ingraph_route, #route::options),
__ingraph_asked,
__ingraph_depth,
)
.await?;
__ingraph_members.push((
__ingraph_weight,
::core::iter::Iterator::collect::<::std::vec::Vec<_>>(
::core::iter::Iterator::map(
::std::vec::Vec::into_iter(__ingraph_ranked),
|__ingraph_hit| {
let (__ingraph_root, __ingraph_rank, __ingraph_seen) =
__ingraph_hit.into_components();
#rooted::new(
__ingraph_root,
__ingraph_rank,
#evidence::#variant(__ingraph_seen),
)
},
),
),
));
}
}
}
});
let arms = self.members.iter().map(|member| {
let variant = variant(member);
let arm = self.member_sighting_name(member);
quote! {
#evidence::#variant(__ingraph_at) => #sighting::#variant(
#arm::new(__ingraph_at, __ingraph_ordinal, __ingraph_contribution),
),
}
});
let asked_parameter = self.asked_parameter();
quote! {
async fn #ask(
__ingraph_ctx: &#ag::Context<'_>,
__ingraph_word: &::core::primitive::str,
__ingraph_broadcast: &#broadcast_ty,
__ingraph_first: ::core::primitive::u32,
__ingraph_depth: ::core::option::Option<::core::primitive::u32>,
#asked_parameter
) -> #ag::Result<
::std::vec::Vec<(#root, ::core::primitive::f64, ::std::vec::Vec<#sighting>)>,
> {
let ::core::option::Option::Some(__ingraph_budget) =
::core::num::NonZeroU32::new(__ingraph_first)
else {
return ::core::result::Result::Ok(::std::vec::Vec::new());
};
let __ingraph_budget = ::core::result::Result::unwrap_or(
<::core::num::NonZeroUsize as ::core::convert::TryFrom<::core::num::NonZeroU32>>::try_from(
__ingraph_budget,
),
::core::num::NonZeroUsize::MAX,
);
let limit = #depth_law(
::core::option::Option::map(
::core::option::Option::and_then(__ingraph_depth, ::core::num::NonZeroU32::new),
|__ingraph_asked| ::core::result::Result::unwrap_or(
<::core::num::NonZeroUsize as ::core::convert::TryFrom<
::core::num::NonZeroU32,
>>::try_from(__ingraph_asked),
::core::num::NonZeroUsize::MAX,
),
),
::core::option::Option::None,
__ingraph_budget,
);
#asked
let question = &__ingraph_question;
let __ingraph_options = #options_package::new();
#(#edges)*
let options = ::core::option::Option::Some(&__ingraph_options);
let __ingraph_fusion = ::core::option::Option::map_or(
::core::option::Option::and_then(options, #options_package::fusion),
<#fusion as ::core::default::Default>::default(),
#flavour::fusion,
);
let mut __ingraph_members = ::std::vec::Vec::new();
#(#reads)*
let mut __ingraph_fused =
#weighted::<_, _, #join<#root>>(__ingraph_members, __ingraph_fusion);
::std::vec::Vec::truncate(
&mut __ingraph_fused,
::core::num::NonZeroUsize::get(__ingraph_budget),
);
::core::result::Result::Ok(::core::iter::Iterator::collect(
::core::iter::Iterator::map(
::std::vec::Vec::into_iter(__ingraph_fused),
|__ingraph_row| {
let (__ingraph_score, __ingraph_root, __ingraph_evidence) =
#fused::into_components(__ingraph_row);
(
__ingraph_root,
#fused_score::get(&__ingraph_score),
::core::iter::Iterator::collect(::core::iter::Iterator::map(
::std::vec::Vec::into_iter(__ingraph_evidence),
|__ingraph_seen| {
let (__ingraph_contribution, __ingraph_ordinal, __ingraph_member) =
#sighting_of::into_components(__ingraph_seen);
match __ingraph_member {
#(#arms)*
}
},
)),
)
},
),
))
}
}
}
fn stretch_fn(&self) -> proc_macro2::TokenStream {
let krate = &self.krate;
let ag = framework(krate, &[], "async_graphql");
let keeper = framework(krate, &["retrieve"], "SnapshotKeeper");
let installed = framework(krate, &["retrieve"], "installed_keeper");
let page_token = framework(krate, &["retrieve"], "PageToken");
let stretch_of = framework(krate, &["retrieve"], "Stretch");
let depth_law = framework(krate, &["retrieve"], "route_depth");
let ask = self.ask_name();
let stretch = self.stretch_fn_name();
let sighting = self.sighting_name();
let root = self.root();
let seat_ty = self.broadcast_ty();
let asked_parameter = self.asked_parameter();
let handed_request = if self.asked_tower().is_some() {
quote!(__ingraph_request,)
} else {
proc_macro2::TokenStream::new()
};
quote! {
async fn #stretch(
__ingraph_ctx: &#ag::Context<'_>,
__ingraph_word: &'static ::core::primitive::str,
__ingraph_broadcast: ::core::option::Option<#seat_ty>,
__ingraph_first: ::core::primitive::u32,
__ingraph_depth: ::core::option::Option<::core::primitive::u32>,
__ingraph_page_token: ::core::option::Option<::std::string::String>,
#asked_parameter
) -> #ag::Result<
#stretch_of<(#root, ::core::primitive::f64, ::std::vec::Vec<#sighting>)>,
> {
let ::core::option::Option::Some(__ingraph_want) =
::core::num::NonZeroU32::new(__ingraph_first)
else {
return ::core::result::Result::Ok(#stretch_of::empty());
};
let __ingraph_want = ::core::result::Result::unwrap_or(
<::core::num::NonZeroUsize as ::core::convert::TryFrom<::core::num::NonZeroU32>>::try_from(
__ingraph_want,
),
::core::num::NonZeroUsize::MAX,
);
let __ingraph_keeper = #installed(__ingraph_ctx, __ingraph_word)?;
let __ingraph_held = match (__ingraph_broadcast, __ingraph_page_token) {
(
::core::option::Option::Some(_),
::core::option::Option::Some(_),
) => {
return ::core::result::Result::Err(#ag::Error::new(::std::format!(
"`{}` takes EITHER a question or a page token: a page token resumes an answer this \
deployment is already holding and a question asks for a new one, so a request \
naming both leaves it unsaid which of the two it meant",
__ingraph_word,
)));
}
(
::core::option::Option::None,
::core::option::Option::None,
) => {
return ::core::result::Result::Err(#ag::Error::new(::std::format!(
"`{}` takes a question to ask or a page token to resume a kept answer, and this \
request named neither",
__ingraph_word,
)));
}
(
::core::option::Option::None,
::core::option::Option::Some(__ingraph_text),
) => {
match <#page_token as ::core::str::FromStr>::from_str(&__ingraph_text) {
::core::result::Result::Ok(__ingraph_held) => __ingraph_held,
::core::result::Result::Err(__ingraph_refusal) => {
return ::core::result::Result::Err(#ag::Error::new(
::std::string::ToString::to_string(&__ingraph_refusal),
));
}
}
}
(
::core::option::Option::Some(__ingraph_asked),
::core::option::Option::None,
) => {
let __ingraph_ceiling = #keeper::depth(__ingraph_keeper);
let __ingraph_wall = ::core::num::NonZeroU32::new(
::core::result::Result::unwrap_or(
<::core::primitive::u32 as ::core::convert::TryFrom<
::core::primitive::usize,
>>::try_from(::core::num::NonZeroUsize::get(__ingraph_ceiling)),
::core::primitive::u32::MAX,
),
);
let __ingraph_capture = #depth_law(
::core::option::Option::map(
::core::option::Option::and_then(__ingraph_depth, ::core::num::NonZeroU32::new),
|__ingraph_deep| ::core::result::Result::unwrap_or(
<::core::num::NonZeroUsize as ::core::convert::TryFrom<
::core::num::NonZeroU32,
>>::try_from(__ingraph_deep),
::core::num::NonZeroUsize::MAX,
),
),
::core::option::Option::as_ref(&__ingraph_wall),
__ingraph_ceiling,
);
let __ingraph_rows = #ask(
__ingraph_ctx,
__ingraph_word,
&__ingraph_asked,
::core::result::Result::unwrap_or(
<::core::primitive::u32 as ::core::convert::TryFrom<
::core::primitive::usize,
>>::try_from(::core::num::NonZeroUsize::get(__ingraph_capture)),
::core::primitive::u32::MAX,
),
__ingraph_depth,
#handed_request
)
.await?;
#keeper::keep(__ingraph_keeper, __ingraph_word, __ingraph_rows)
}
};
match #keeper::read::<
(#root, ::core::primitive::f64, ::std::vec::Vec<#sighting>),
>(__ingraph_keeper, &__ingraph_held, __ingraph_word, __ingraph_want) {
::core::result::Result::Ok(__ingraph_stretch) => {
::core::result::Result::Ok(__ingraph_stretch)
}
::core::result::Result::Err(__ingraph_refusal) => {
::core::result::Result::Err(#ag::Error::new(
::std::string::ToString::to_string(&__ingraph_refusal),
))
}
}
}
}
}
fn query_fields(&self) -> proc_macro2::TokenStream {
let krate = &self.krate;
let ag = framework(krate, &[], "async_graphql");
let wire = framework(krate, &["graphql"], "WireRoot");
let recipe = &self.name;
let ask = self.ask_name();
let key_match = self.key_match_name();
let hydrated_match = self.match_name();
let root = self.root();
let seat_ty = self.broadcast_ty();
let seat_sdl = self.broadcast_word();
let keys_sdl = self.field_name(true);
let hydrated_sdl = self.field_name(false);
let keys_method = crate::method::wire_method(&format_ident!("{}", snake(&keys_sdl)));
let hydrated_method = crate::method::wire_method(&format_ident!("{}", snake(&hydrated_sdl)));
let (ctx, broadcast, first, depth, page_token) = (
crate::method::wire_method(&format_ident!("ctx")),
self.broadcast_binding(),
crate::method::wire_method(&format_ident!("first")),
crate::method::wire_method(&format_ident!("depth")),
crate::method::wire_method(&format_ident!("page_token")),
);
let asked = crate::method::wire_method(&format_ident!("options"));
let asked_argument = self.asked_argument(&asked);
let handed = if self.asked_tower().is_some() {
quote!(#asked,)
} else {
proc_macro2::TokenStream::new()
};
let stretch = self.stretch_fn_name();
let stretch_of = framework(krate, &["retrieve"], "Stretch");
let key_stretch = self.stretch_name(true);
let hydrated_stretch = self.stretch_name(false);
let keys_stretch_sdl = self.stretch_field_name(true);
let hydrated_stretch_sdl = self.stretch_field_name(false);
let keys_stretch_method =
crate::method::wire_method(&format_ident!("{}", snake(&keys_stretch_sdl)));
let hydrated_stretch_method =
crate::method::wire_method(&format_ident!("{}", snake(&hydrated_stretch_sdl)));
let keys_stretch_doc = leading(&format!(
"ONE STRETCH of the addresses [`{recipe}`] ranks nearest one question — the fused ranking \
computed ONCE and held, then walked a stretch at a time.\n\nTakes EITHER a question, which \
computes a fresh ranking and keeps it, OR the `pageToken` a previous stretch answered with, \
which cuts the next stretch off the ranking already held — no member is asked and no tower \
is walked on a resume. A page token whose answer has expired, been evicted, or was minted \
elsewhere is refused BY NAME rather than answered with an empty stretch."
));
let hydrated_stretch_doc = leading(&format!(
"ONE STRETCH of the rows [`{recipe}`] ranks nearest one question — the keys tier's own \
stretch with each address resolved, in the same order and with the same provenance.\n\nThe \
snapshot holds addresses only, so hydration happens per stretch: the rows a client never \
walks to are never read."
));
let default = syn::LitInt::new(&self.wire_first().to_string(), self.name.span());
let keys_doc = leading(&format!(
"The ADDRESSES [`{recipe}`] ranks nearest one question — every member it lists asked at once, \
their rankings joined by reciprocal rank fusion."
));
let hydrated_doc = leading(&format!(
"The ROWS [`{recipe}`] ranks nearest one question — the keys tier's own answer with each \
address resolved, in the same order and with the same provenance."
));
let hydrated_half = quote! {
#[doc = #hydrated_doc]
#[graphql(name = #hydrated_sdl)]
async fn #hydrated_method(
&self,
#ctx: &#ag::Context<'_>,
#[graphql(name = #seat_sdl)] #broadcast: #seat_ty,
#[graphql(name = "first", default = #default)] #first: ::core::primitive::u32,
#[graphql(name = "depth")] #depth: ::core::option::Option<::core::primitive::u32>,
#asked_argument
) -> #ag::Result<::std::vec::Vec<#hydrated_match>> {
let __ingraph_answered =
#ask(#ctx, #hydrated_sdl, &#broadcast, #first, #depth, #handed).await?;
let mut __ingraph_keys: ::std::vec::Vec<#root> = ::std::vec::Vec::new();
let mut __ingraph_rest = ::std::vec::Vec::new();
for (__ingraph_key, __ingraph_score, __ingraph_evidence) in __ingraph_answered {
::std::vec::Vec::push(&mut __ingraph_keys, __ingraph_key);
::std::vec::Vec::push(&mut __ingraph_rest, (__ingraph_score, __ingraph_evidence));
}
let __ingraph_rows = <#root as #wire>::hydrate(#ctx, __ingraph_keys).await?;
::core::result::Result::Ok(::core::iter::Iterator::collect(
::core::iter::Iterator::filter_map(
::core::iter::Iterator::zip(
::std::vec::Vec::into_iter(__ingraph_rows),
::std::vec::Vec::into_iter(__ingraph_rest),
),
|(__ingraph_row, (__ingraph_score, __ingraph_evidence))| {
::core::option::Option::map(__ingraph_row, |__ingraph_entity| {
#hydrated_match::new(__ingraph_entity, __ingraph_score, __ingraph_evidence)
})
},
),
))
}
};
quote! {
#[doc = #keys_doc]
#[graphql(name = #keys_sdl)]
async fn #keys_method(
&self,
#ctx: &#ag::Context<'_>,
#[graphql(name = #seat_sdl)] #broadcast: #seat_ty,
#[graphql(name = "first", default = #default)] #first: ::core::primitive::u32,
#[graphql(name = "depth")] #depth: ::core::option::Option<::core::primitive::u32>,
#asked_argument
) -> #ag::Result<::std::vec::Vec<#key_match>> {
let __ingraph_answered =
#ask(#ctx, #keys_sdl, &#broadcast, #first, #depth, #handed).await?;
::core::result::Result::Ok(::core::iter::Iterator::collect(
::core::iter::Iterator::map(
::std::vec::Vec::into_iter(__ingraph_answered),
|(__ingraph_root, __ingraph_score, __ingraph_evidence)| #key_match::new(
<#root as #wire>::address(__ingraph_root),
__ingraph_score,
__ingraph_evidence,
),
),
))
}
#hydrated_half
#[doc = #keys_stretch_doc]
#[graphql(name = #keys_stretch_sdl)]
async fn #keys_stretch_method(
&self,
#ctx: &#ag::Context<'_>,
#[graphql(name = #seat_sdl)] #broadcast: ::core::option::Option<#seat_ty>,
#[graphql(name = "first", default = #default)] #first: ::core::primitive::u32,
#[graphql(name = "depth")] #depth: ::core::option::Option<::core::primitive::u32>,
#[graphql(name = "pageToken")] #page_token: ::core::option::Option<::std::string::String>,
#asked_argument
) -> #ag::Result<#key_stretch> {
let __ingraph_cut = #stretch(
#ctx, #keys_stretch_sdl, #broadcast, #first, #depth, #page_token, #handed
).await?;
let (__ingraph_rows, __ingraph_next) = #stretch_of::into_components(__ingraph_cut);
::core::result::Result::Ok(#key_stretch::new(
::core::iter::Iterator::collect(::core::iter::Iterator::map(
::std::vec::Vec::into_iter(__ingraph_rows),
|(__ingraph_root, __ingraph_score, __ingraph_evidence)| #key_match::new(
<#root as #wire>::address(__ingraph_root),
__ingraph_score,
__ingraph_evidence,
),
)),
::core::option::Option::map(__ingraph_next, |__ingraph_claim| {
::std::string::ToString::to_string(&__ingraph_claim)
}),
))
}
#[doc = #hydrated_stretch_doc]
#[graphql(name = #hydrated_stretch_sdl)]
async fn #hydrated_stretch_method(
&self,
#ctx: &#ag::Context<'_>,
#[graphql(name = #seat_sdl)] #broadcast: ::core::option::Option<#seat_ty>,
#[graphql(name = "first", default = #default)] #first: ::core::primitive::u32,
#[graphql(name = "depth")] #depth: ::core::option::Option<::core::primitive::u32>,
#[graphql(name = "pageToken")] #page_token: ::core::option::Option<::std::string::String>,
#asked_argument
) -> #ag::Result<#hydrated_stretch> {
let __ingraph_cut = #stretch(
#ctx, #hydrated_stretch_sdl, #broadcast, #first, #depth, #page_token, #handed
).await?;
let (__ingraph_rows, __ingraph_next) = #stretch_of::into_components(__ingraph_cut);
let mut __ingraph_keys: ::std::vec::Vec<#root> = ::std::vec::Vec::new();
let mut __ingraph_rest = ::std::vec::Vec::new();
for (__ingraph_key, __ingraph_score, __ingraph_evidence) in __ingraph_rows {
::std::vec::Vec::push(&mut __ingraph_keys, __ingraph_key);
::std::vec::Vec::push(&mut __ingraph_rest, (__ingraph_score, __ingraph_evidence));
}
let __ingraph_hydrated = <#root as #wire>::hydrate(#ctx, __ingraph_keys).await?;
::core::result::Result::Ok(#hydrated_stretch::new(
::core::iter::Iterator::collect(::core::iter::Iterator::filter_map(
::core::iter::Iterator::zip(
::std::vec::Vec::into_iter(__ingraph_hydrated),
::std::vec::Vec::into_iter(__ingraph_rest),
),
|(__ingraph_row, (__ingraph_score, __ingraph_evidence))| {
::core::option::Option::map(__ingraph_row, |__ingraph_entity| {
#hydrated_match::new(__ingraph_entity, __ingraph_score, __ingraph_evidence)
})
},
)),
::core::option::Option::map(__ingraph_next, |__ingraph_claim| {
::std::string::ToString::to_string(&__ingraph_claim)
}),
))
}
}
}
fn wire_first(&self) -> core::num::NonZeroU32 {
self.limit.unwrap_or(crate::index::FRAMEWORK_LIMIT)
}
}
fn variant(member: &MemberModel) -> syn::Ident {
format_ident!("{}", member.field.to_string().to_upper_camel_case())
}
const ASK: &str = "ask";
enum Producer<'a> {
Arm(&'a ArmModel, &'a SharedBinding),
Broadcast,
Elsewhere,
}