Fix compilation and tests
This commit is contained in:
parent
768b666acd
commit
4b20a21783
|
@ -100,19 +100,19 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
|
|||
Some(meta) => generate_guards(&crate_name, &meta)?,
|
||||
None => None,
|
||||
};
|
||||
let guard = guard.map(|guard| quote! { #guard.check(ctx).await.map_err(|err| err.into_error_with_path(ctx.item.pos, ctx.path_node.as_ref()))?; });
|
||||
let guard = guard.map(|guard| quote! { #guard.check(ctx).await.map_err(|err| err.into_server_error().at(ctx.item.pos))?; });
|
||||
|
||||
let post_guard = match &field.post_guard {
|
||||
Some(meta) => generate_post_guards(&crate_name, &meta)?,
|
||||
None => None,
|
||||
};
|
||||
let post_guard = post_guard.map(|guard| quote! { #guard.check(ctx, &res).await.map_err(|err| err.into_error_with_path(ctx.item.pos, ctx.path_node.as_ref()))?; });
|
||||
let post_guard = post_guard.map(|guard| quote! { #guard.check(ctx, &res).await.map_err(|err| err.into_server_error().at(ctx.item.pos))?; });
|
||||
|
||||
getters.push(if !field.owned {
|
||||
quote! {
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
#vis async fn #ident(&self, ctx: &#crate_name::Context<'_>) -> #crate_name::FieldResult<&#ty> {
|
||||
#vis async fn #ident(&self, ctx: &#crate_name::Context<'_>) -> #crate_name::Result<&#ty> {
|
||||
Ok(&self.#ident)
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
|
|||
quote! {
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
#vis async fn #ident(&self, ctx: &#crate_name::Context<'_>) -> #crate_name::FieldResult<#ty> {
|
||||
#vis async fn #ident(&self, ctx: &#crate_name::Context<'_>) -> #crate_name::Result<#ty> {
|
||||
Ok(self.#ident.clone())
|
||||
}
|
||||
}
|
||||
|
@ -129,10 +129,10 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
|
|||
resolvers.push(quote! {
|
||||
if ctx.item.node.name.node == #field_name {
|
||||
#guard
|
||||
let res = self.#ident(ctx).await.map_err(|err| err.into_error_with_path(ctx.item.pos, ctx.path_node.as_ref()))?;
|
||||
let res = self.#ident(ctx).await.map_err(|err| err.into_server_error().at(ctx.item.pos))?;
|
||||
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
|
||||
#post_guard
|
||||
return #crate_name::OutputValueType::resolve(&res, &ctx_obj, ctx.item).await;
|
||||
return #crate_name::OutputValueType::resolve(&res, &ctx_obj, ctx.item).await.map(::std::option::Option::Some);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ pub fn generate(
|
|||
};
|
||||
let param_getter_name = get_param_getter_ident(&ident.ident.to_string());
|
||||
get_params.push(quote! {
|
||||
let #param_getter_name = || -> #crate_name::Result<#ty> { ctx.param_value(#name, #default) };
|
||||
let #param_getter_name = || -> #crate_name::ServerResult<#ty> { ctx.param_value(#name, #default) };
|
||||
let #ident: #ty = ctx.param_value(#name, #default)?;
|
||||
});
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ pub fn generate(
|
|||
});
|
||||
method.block = syn::parse2::<Block>(new_block).expect("invalid block");
|
||||
method.sig.output =
|
||||
syn::parse2::<ReturnType>(quote! { -> #crate_name::FieldResult<#inner_ty> })
|
||||
syn::parse2::<ReturnType>(quote! { -> #crate_name::Result<#inner_ty> })
|
||||
.expect("invalid result type");
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,7 @@ pub fn generate(
|
|||
self.#ident(ctx, #(#use_params),*)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.into_error_with_path(ctx.item.pos, ctx.path_node.as_ref())
|
||||
err.into_server_error().at(ctx.item.pos)
|
||||
})?
|
||||
};
|
||||
|
||||
|
@ -258,7 +258,7 @@ pub fn generate(
|
|||
None => None,
|
||||
};
|
||||
let guard = guard.map(|guard| quote! {
|
||||
#guard.check(ctx).await.map_err(|err| err.into_error_with_path(ctx.item.pos, ctx.path_node.as_ref()))?;
|
||||
#guard.check(ctx).await.map_err(|err| err.into_server_error().at(ctx.item.pos))?;
|
||||
});
|
||||
if field.post_guard.is_some() {
|
||||
return Err(Error::new_spanned(
|
||||
|
@ -321,11 +321,12 @@ pub fn generate(
|
|||
|
||||
#crate_name::extensions::Extension::resolve_end(&mut *query_env.extensions.lock(), &ctx_extension, &ri);
|
||||
#crate_name::extensions::Extension::execution_end(&mut *query_env.extensions.lock(), &ctx_extension);
|
||||
(field_name.to_string(), res)
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
});
|
||||
#crate_name::Result::Ok(#crate_name::futures::StreamExt::scan(
|
||||
#crate_name::ServerResult::Ok(#crate_name::futures::StreamExt::scan(
|
||||
stream,
|
||||
false,
|
||||
|errored, item| {
|
||||
|
|
|
@ -66,7 +66,7 @@ impl Extension for LoggerExtension {
|
|||
|
||||
fn error(&mut self, _ctx: &ExtensionContext<'_>, err: &ServerError) {
|
||||
struct DisplayError<'a> {
|
||||
log: &'a Logger,
|
||||
log: &'a LoggerExtension,
|
||||
e: &'a ServerError,
|
||||
};
|
||||
impl<'a> Display for DisplayError<'a> {
|
||||
|
|
|
@ -8,7 +8,7 @@ mod logger;
|
|||
mod tracing;
|
||||
|
||||
use crate::context::{QueryPathNode, ResolveId};
|
||||
use crate::{Data, QueryEnv, Result, SchemaEnv, ServerError, ServerResult, Variables};
|
||||
use crate::{Data, Result, ServerError, ServerResult, Variables};
|
||||
|
||||
#[cfg(feature = "apollo_tracing")]
|
||||
pub use self::apollo_tracing::ApolloTracing;
|
||||
|
@ -147,11 +147,11 @@ impl<T> ErrorLogger for ServerResult<T> {
|
|||
}
|
||||
}
|
||||
impl<T> ErrorLogger for Result<T, Vec<ServerError>> {
|
||||
fn log_error(self, extensions: &spin::Mutex<Extensions>) -> Self {
|
||||
fn log_error(self, ctx: &ExtensionContext<'_>, extensions: &spin::Mutex<Extensions>) -> Self {
|
||||
if let Err(errors) = &self {
|
||||
let mut extensions = extensions.lock();
|
||||
for error in errors {
|
||||
extensions.error(error);
|
||||
extensions.error(ctx, error);
|
||||
}
|
||||
}
|
||||
self
|
||||
|
|
|
@ -9,8 +9,8 @@ use crate::subscription::collect_subscription_streams;
|
|||
use crate::types::QueryRoot;
|
||||
use crate::validation::{check_rules, CheckResult, ValidationMode};
|
||||
use crate::{
|
||||
BatchRequest, BatchResponse, CacheControl, ContextBase, Pos, Positioned, QueryEnv, Request,
|
||||
Response, ServerError, SubscriptionType, Type, Variables, ID,
|
||||
BatchRequest, BatchResponse, CacheControl, ContextBase, QueryEnv, Request, Response,
|
||||
ServerError, SubscriptionType, Type, ID,
|
||||
};
|
||||
use futures::stream::{self, Stream, StreamExt};
|
||||
use indexmap::map::IndexMap;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::parser::types::Field;
|
||||
use crate::registry::{MetaType, Registry};
|
||||
use crate::resolver_utils::{resolve_object, ObjectType};
|
||||
use crate::type_mark::{TypeMarkObject, TypeMarkSubscription};
|
||||
use crate::type_mark::TypeMarkObject;
|
||||
use crate::{
|
||||
CacheControl, Context, ContextSelectionSet, OutputValueType, Positioned, ServerResult,
|
||||
SimpleObject, Subscription, Type,
|
||||
|
|
|
@ -88,7 +88,7 @@ pub async fn test_field_features() {
|
|||
message: r#"Unknown field "valueAbc" on type "QueryRoot". Did you mean "value"?"#
|
||||
.to_owned(),
|
||||
locations: vec![Pos { column: 3, line: 1 }],
|
||||
path: vec![PathSegment::Field("valueAbc".to_owned())],
|
||||
path: Vec::new(),
|
||||
extensions: None,
|
||||
}]
|
||||
);
|
||||
|
@ -116,10 +116,7 @@ pub async fn test_field_features() {
|
|||
message: r#"Unknown field "valueAbc" on type "MyObj". Did you mean "value"?"#
|
||||
.to_owned(),
|
||||
locations: vec![Pos { column: 9, line: 1 }],
|
||||
path: vec![
|
||||
PathSegment::Field("obj".to_owned()),
|
||||
PathSegment::Field("valueAbc".to_owned())
|
||||
],
|
||||
path: Vec::new(),
|
||||
extensions: None,
|
||||
}]
|
||||
);
|
||||
|
@ -152,12 +149,12 @@ pub async fn test_field_features() {
|
|||
.unwrap()
|
||||
.errors,
|
||||
vec![ServerError {
|
||||
message: r#"Unknown field "valuesAbc" on type "SubscriptionRoot". Did you mean "values", "valuesBson"?"#,
|
||||
message: r#"Unknown field "valuesAbc" on type "SubscriptionRoot". Did you mean "values", "valuesBson"?"#.to_owned(),
|
||||
locations: vec![Pos {
|
||||
column: 16,
|
||||
line: 1
|
||||
}],
|
||||
path: vec![PathSegment::Field("valuesAbc".to_owned())],
|
||||
path: Vec::new(),
|
||||
extensions: None,
|
||||
}]
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user