Rename InputValueType to InputType and OutputValueType to OutputType.

This commit is contained in:
Sunli 2020-12-11 15:37:50 +08:00
parent d39a2f55a9
commit 03f6ed4ba2
38 changed files with 150 additions and 165 deletions

View File

@ -28,9 +28,9 @@ which keeps track of how deeply nested the query gets as the document is walked
At this point all the unnecessary operations (ones not selected by `operationName`) are dropped, and At this point all the unnecessary operations (ones not selected by `operationName`) are dropped, and
we will execute just one. we will execute just one.
At the core of all the resolver logic there are two traits: `InputValueType` and `OutputValueType` At the core of all the resolver logic there are two traits: `InputType` and `OutputType`
which represent a GraphQL input value and GraphQL output value respectively. `InputValueType` just which represent a GraphQL input value and GraphQL output value respectively. `InputType` just
requires conversions to and from `async_graphql::Value`. `OutputValueType` is an async trait with a requires conversions to and from `async_graphql::Value`. `OutputType` is an async trait with a
single method, `resolve`, which takes a field (e.g. `user(name: "sunli829") { display_name }`) and single method, `resolve`, which takes a field (e.g. `user(name: "sunli829") { display_name }`) and
resolves it to a single value. resolves it to a single value.
@ -38,5 +38,5 @@ Scalars and enums are expected to ignore the input and serialize themselves, whi
interfaces and unions are expected to read the selection set in the field and resolve and serialize interfaces and unions are expected to read the selection set in the field and resolve and serialize
each one of their fields. each one of their fields.
As implementing `OutputValueType::resolve` manually quickly becomes very tedious helpful utilities As implementing `OutputType::resolve` manually quickly becomes very tedious helpful utilities
are provided in the `resolver_utils` module and via macros. are provided in the `resolver_utils` module and via macros.

View File

@ -149,7 +149,7 @@ pub fn generate(enum_args: &args::Enum) -> GeneratorResult<TokenStream> {
} }
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
impl #crate_name::InputValueType for #ident { impl #crate_name::InputType for #ident {
fn parse(value: ::std::option::Option<#crate_name::Value>) -> #crate_name::InputValueResult<Self> { fn parse(value: ::std::option::Option<#crate_name::Value>) -> #crate_name::InputValueResult<Self> {
#crate_name::resolver_utils::parse_enum(value.unwrap_or_default()) #crate_name::resolver_utils::parse_enum(value.unwrap_or_default())
} }
@ -160,7 +160,7 @@ pub fn generate(enum_args: &args::Enum) -> GeneratorResult<TokenStream> {
} }
#[#crate_name::async_trait::async_trait] #[#crate_name::async_trait::async_trait]
impl #crate_name::OutputValueType for #ident { impl #crate_name::OutputType for #ident {
async fn resolve(&self, _: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> { async fn resolve(&self, _: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> {
::std::result::Result::Ok(#crate_name::resolver_utils::enum_value(*self)) ::std::result::Result::Ok(#crate_name::resolver_utils::enum_value(*self))
} }

View File

@ -74,7 +74,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
}); });
get_fields.push(quote! { get_fields.push(quote! {
let #ident: #ty = #crate_name::InputValueType::parse( let #ident: #ty = #crate_name::InputType::parse(
::std::option::Option::Some(#crate_name::Value::Object(::std::clone::Clone::clone(&obj))) ::std::option::Option::Some(#crate_name::Value::Object(::std::clone::Clone::clone(&obj)))
).map_err(#crate_name::InputValueError::propagate)?; ).map_err(#crate_name::InputValueError::propagate)?;
}); });
@ -82,7 +82,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
fields.push(ident); fields.push(ident);
put_fields.push(quote! { put_fields.push(quote! {
if let #crate_name::Value::Object(values) = #crate_name::InputValueType::to_value(&self.#ident) { if let #crate_name::Value::Object(values) = #crate_name::InputType::to_value(&self.#ident) {
map.extend(values); map.extend(values);
} }
}); });
@ -105,7 +105,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
.map(|value| { .map(|value| {
quote! { quote! {
::std::option::Option::Some(::std::string::ToString::to_string( ::std::option::Option::Some(::std::string::ToString::to_string(
&<#ty as #crate_name::InputValueType>::to_value(&#value) &<#ty as #crate_name::InputType>::to_value(&#value)
)) ))
} }
}) })
@ -117,7 +117,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
let #ident: #ty = { let #ident: #ty = {
match obj.get(#name) { match obj.get(#name) {
::std::option::Option::Some(value) => { ::std::option::Option::Some(value) => {
#crate_name::InputValueType::parse(::std::option::Option::Some(::std::clone::Clone::clone(&value))) #crate_name::InputType::parse(::std::option::Option::Some(::std::clone::Clone::clone(&value)))
.map_err(#crate_name::InputValueError::propagate)? .map_err(#crate_name::InputValueError::propagate)?
}, },
::std::option::Option::None => #default, ::std::option::Option::None => #default,
@ -127,7 +127,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
} else { } else {
get_fields.push(quote! { get_fields.push(quote! {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let #ident: #ty = #crate_name::InputValueType::parse(obj.get(#name).cloned()) let #ident: #ty = #crate_name::InputType::parse(obj.get(#name).cloned())
.map_err(#crate_name::InputValueError::propagate)?; .map_err(#crate_name::InputValueError::propagate)?;
}); });
} }
@ -135,7 +135,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
put_fields.push(quote! { put_fields.push(quote! {
map.insert( map.insert(
#crate_name::Name::new(#name), #crate_name::Name::new(#name),
#crate_name::InputValueType::to_value(&self.#ident) #crate_name::InputType::to_value(&self.#ident)
); );
}); });
@ -180,7 +180,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
} }
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
impl #crate_name::InputValueType for #ident { impl #crate_name::InputType for #ident {
fn parse(value: ::std::option::Option<#crate_name::Value>) -> #crate_name::InputValueResult<Self> { fn parse(value: ::std::option::Option<#crate_name::Value>) -> #crate_name::InputValueResult<Self> {
if let ::std::option::Option::Some(#crate_name::Value::Object(obj)) = value { if let ::std::option::Option::Some(#crate_name::Value::Object(obj)) = value {
#(#get_fields)* #(#get_fields)*

View File

@ -210,7 +210,7 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
.map(|value| { .map(|value| {
quote! { quote! {
::std::option::Option::Some(::std::string::ToString::to_string( ::std::option::Option::Some(::std::string::ToString::to_string(
&<#ty as #crate_name::InputValueType>::to_value(&#value) &<#ty as #crate_name::InputType>::to_value(&#value)
)) ))
} }
}) })
@ -285,7 +285,7 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
if ctx.item.node.name.node == #name { if ctx.item.node.name.node == #name {
#(#get_params)* #(#get_params)*
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return #crate_name::OutputValueType::resolve(&#resolve_obj, &ctx_obj, ctx.item).await.map(::std::option::Option::Some); return #crate_name::OutputType::resolve(&#resolve_obj, &ctx_obj, ctx.item).await.map(::std::option::Option::Some);
} }
}); });
} }
@ -359,7 +359,7 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
#[#crate_name::async_trait::async_trait] #[#crate_name::async_trait::async_trait]
impl #generics #crate_name::OutputValueType for #ident #generics { impl #generics #crate_name::OutputType for #ident #generics {
async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> { async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> {
#crate_name::resolver_utils::resolve_container(ctx, self).await #crate_name::resolver_utils::resolve_container(ctx, self).await
} }

View File

@ -102,7 +102,7 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
#[#crate_name::async_trait::async_trait] #[#crate_name::async_trait::async_trait]
impl #generics #crate_name::OutputValueType for #ident #generics #where_clause { impl #generics #crate_name::OutputType for #ident #generics #where_clause {
async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> { async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> {
#crate_name::resolver_utils::resolve_container(ctx, self).await #crate_name::resolver_utils::resolve_container(ctx, self).await
} }

View File

@ -95,7 +95,7 @@ pub fn generate(
{ {
return Err(Error::new_spanned( return Err(Error::new_spanned(
arg, arg,
"Only types that implement `InputValueType` can be used as input arguments.", "Only types that implement `InputType` can be used as input arguments.",
) )
.into()); .into());
} else { } else {
@ -152,7 +152,7 @@ pub fn generate(
}); });
key_getter.push(quote! { key_getter.push(quote! {
params.get(#name).and_then(|value| { params.get(#name).and_then(|value| {
let value: ::std::option::Option<#ty> = #crate_name::InputValueType::parse(::std::option::Option::Some(::std::clone::Clone::clone(&value))).ok(); let value: ::std::option::Option<#ty> = #crate_name::InputType::parse(::std::option::Option::Some(::std::clone::Clone::clone(&value))).ok();
value value
}) })
}); });
@ -161,7 +161,7 @@ pub fn generate(
} else { } else {
// requires // requires
requires_getter.push(quote! { requires_getter.push(quote! {
let #ident: #ty = #crate_name::InputValueType::parse(params.get(#name).cloned()). let #ident: #ty = #crate_name::InputType::parse(params.get(#name).cloned()).
map_err(|err| err.into_server_error().at(ctx.item.pos))?; map_err(|err| err.into_server_error().at(ctx.item.pos))?;
}); });
use_keys.push(ident); use_keys.push(ident);
@ -197,7 +197,7 @@ pub fn generate(
if let (#(#key_pat),*) = (#(#key_getter),*) { if let (#(#key_pat),*) = (#(#key_getter),*) {
#(#requires_getter)* #(#requires_getter)*
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return #crate_name::OutputValueType::resolve(&#do_find, &ctx_obj, ctx.item).await.map(::std::option::Option::Some); return #crate_name::OutputType::resolve(&#do_find, &ctx_obj, ctx.item).await.map(::std::option::Option::Some);
} }
} }
}, },
@ -285,7 +285,7 @@ pub fn generate(
{ {
return Err(Error::new_spanned( return Err(Error::new_spanned(
arg, arg,
"Only types that implement `InputValueType` can be used as input arguments.", "Only types that implement `InputType` can be used as input arguments.",
) )
.into()); .into());
} }
@ -338,7 +338,7 @@ pub fn generate(
.map(|value| { .map(|value| {
quote! { quote! {
::std::option::Option::Some(::std::string::ToString::to_string( ::std::option::Option::Some(::std::string::ToString::to_string(
&<#ty as #crate_name::InputValueType>::to_value(&#value) &<#ty as #crate_name::InputType>::to_value(&#value)
)) ))
} }
}) })
@ -442,7 +442,7 @@ pub fn generate(
#guard #guard
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
let res = #resolve_obj; let res = #resolve_obj;
return #crate_name::OutputValueType::resolve(&res, &ctx_obj, ctx.item).await.map(::std::option::Option::Some); return #crate_name::OutputType::resolve(&res, &ctx_obj, ctx.item).await.map(::std::option::Option::Some);
} }
}); });
} }
@ -530,7 +530,7 @@ pub fn generate(
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
#[#crate_name::async_trait::async_trait] #[#crate_name::async_trait::async_trait]
impl #generics #crate_name::OutputValueType for #self_ty #where_clause { impl #generics #crate_name::OutputType for #self_ty #where_clause {
async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> { async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> {
#crate_name::resolver_utils::resolve_container(ctx, self).await #crate_name::resolver_utils::resolve_container(ctx, self).await
} }

View File

@ -46,7 +46,7 @@ pub fn generate(
} }
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
impl #generic #crate_name::InputValueType for #self_ty #where_clause { impl #generic #crate_name::InputType for #self_ty #where_clause {
fn parse(value: ::std::option::Option<#crate_name::Value>) -> #crate_name::InputValueResult<Self> { fn parse(value: ::std::option::Option<#crate_name::Value>) -> #crate_name::InputValueResult<Self> {
<#self_ty as #crate_name::ScalarType>::parse(value.unwrap_or_default()) <#self_ty as #crate_name::ScalarType>::parse(value.unwrap_or_default())
} }
@ -58,7 +58,7 @@ pub fn generate(
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
#[#crate_name::async_trait::async_trait] #[#crate_name::async_trait::async_trait]
impl #generic #crate_name::OutputValueType for #self_ty #where_clause { impl #generic #crate_name::OutputType for #self_ty #where_clause {
async fn resolve( async fn resolve(
&self, &self,
_: &#crate_name::ContextSelectionSet<'_>, _: &#crate_name::ContextSelectionSet<'_>,

View File

@ -124,7 +124,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
#guard #guard
let res = self.#ident(ctx).await.map_err(|err| err.into_server_error().at(ctx.item.pos))?; 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); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return #crate_name::OutputValueType::resolve(&res, &ctx_obj, ctx.item).await.map(::std::option::Option::Some); return #crate_name::OutputType::resolve(&res, &ctx_obj, ctx.item).await.map(::std::option::Option::Some);
} }
}); });
} }
@ -188,7 +188,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
#[#crate_name::async_trait::async_trait] #[#crate_name::async_trait::async_trait]
impl #generics #crate_name::OutputValueType for #ident #generics #where_clause { impl #generics #crate_name::OutputType for #ident #generics #where_clause {
async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> { async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> {
#crate_name::resolver_utils::resolve_container(ctx, self).await #crate_name::resolver_utils::resolve_container(ctx, self).await
} }

View File

@ -115,7 +115,7 @@ pub fn generate(
{ {
return Err(Error::new_spanned( return Err(Error::new_spanned(
arg, arg,
"Only types that implement `InputValueType` can be used as input arguments.", "Only types that implement `InputType` can be used as input arguments.",
) )
.into()); .into());
} else { } else {
@ -177,7 +177,7 @@ pub fn generate(
.map(|value| { .map(|value| {
quote! { quote! {
::std::option::Option::Some(::std::string::ToString::to_string( ::std::option::Option::Some(::std::string::ToString::to_string(
&<#ty as #crate_name::InputValueType>::to_value(&#value) &<#ty as #crate_name::InputType>::to_value(&#value)
)) ))
} }
}) })
@ -319,7 +319,7 @@ pub fn generate(
query_env.extensions.resolve_start(&ctx_extension, &ri); query_env.extensions.resolve_start(&ctx_extension, &ri);
let res = #crate_name::OutputValueType::resolve(&msg, &ctx_selection_set, &*field).await; let res = #crate_name::OutputType::resolve(&msg, &ctx_selection_set, &*field).await;
query_env.extensions.resolve_end(&ctx_extension, &ri); query_env.extensions.resolve_end(&ctx_extension, &ri);
query_env.extensions.execution_end(&ctx_extension); query_env.extensions.execution_end(&ctx_extension);

View File

@ -197,7 +197,7 @@ pub fn generate(union_args: &args::Union) -> GeneratorResult<TokenStream> {
#[allow(clippy::all, clippy::pedantic)] #[allow(clippy::all, clippy::pedantic)]
#[#crate_name::async_trait::async_trait] #[#crate_name::async_trait::async_trait]
impl #generics #crate_name::OutputValueType for #ident #generics { impl #generics #crate_name::OutputType for #ident #generics {
async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> { async fn resolve(&self, ctx: &#crate_name::ContextSelectionSet<'_>, _field: &#crate_name::Positioned<#crate_name::parser::types::Field>) -> #crate_name::ServerResult<#crate_name::Value> {
#crate_name::resolver_utils::resolve_container(ctx, self).await #crate_name::resolver_utils::resolve_container(ctx, self).await
} }

View File

@ -36,7 +36,7 @@ pub trait Type {
} }
/// Represents a GraphQL input value. /// Represents a GraphQL input value.
pub trait InputValueType: Type + Sized { pub trait InputType: Type + Sized {
/// Parse from `Value`. None represents undefined. /// Parse from `Value`. None represents undefined.
fn parse(value: Option<Value>) -> InputValueResult<Self>; fn parse(value: Option<Value>) -> InputValueResult<Self>;
@ -46,7 +46,7 @@ pub trait InputValueType: Type + Sized {
/// Represents a GraphQL output value. /// Represents a GraphQL output value.
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait OutputValueType: Type { pub trait OutputType: Type {
/// Resolve an output value to `async_graphql::Value`. /// Resolve an output value to `async_graphql::Value`.
async fn resolve( async fn resolve(
&self, &self,
@ -66,7 +66,7 @@ impl<T: Type + Send + Sync + ?Sized> Type for &T {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Send + Sync + ?Sized> OutputValueType for &T { impl<T: OutputType + Send + Sync + ?Sized> OutputType for &T {
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
async fn resolve( async fn resolve(
&self, &self,
@ -92,7 +92,7 @@ impl<T: Type> Type for Result<T> {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Sync> OutputValueType for Result<T> { impl<T: OutputType + Sync> OutputType for Result<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,
@ -118,4 +118,4 @@ pub trait InterfaceType: ContainerType {}
pub trait UnionType: ContainerType {} pub trait UnionType: ContainerType {}
/// A GraphQL input object. /// A GraphQL input object.
pub trait InputObjectType: InputValueType {} pub trait InputObjectType: InputType {}

View File

@ -20,7 +20,7 @@ use crate::parser::types::{
}; };
use crate::schema::SchemaEnv; use crate::schema::SchemaEnv;
use crate::{ use crate::{
Error, InputValueType, Lookahead, Name, Pos, Positioned, Result, ServerError, ServerResult, Error, InputType, Lookahead, Name, Pos, Positioned, Result, ServerError, ServerResult,
UploadValue, Value, UploadValue, Value,
}; };
@ -493,7 +493,7 @@ impl<'a, T> ContextBase<'a, T> {
let condition_input = self.resolve_input_value(condition_input)?; let condition_input = self.resolve_input_value(condition_input)?;
if include if include
!= <bool as InputValueType>::parse(Some(condition_input)) != <bool as InputType>::parse(Some(condition_input))
.map_err(|e| e.into_server_error().at(pos))? .map_err(|e| e.into_server_error().at(pos))?
{ {
return Ok(true); return Ok(true);
@ -523,7 +523,7 @@ impl<'a> ContextBase<'a, &'a Positioned<SelectionSet>> {
impl<'a> ContextBase<'a, &'a Positioned<Field>> { impl<'a> ContextBase<'a, &'a Positioned<Field>> {
#[doc(hidden)] #[doc(hidden)]
pub fn param_value<T: InputValueType>( pub fn param_value<T: InputType>(
&self, &self,
name: &str, name: &str,
default: Option<fn() -> T>, default: Option<fn() -> T>,
@ -538,7 +538,7 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
Some(value) => (value.pos, Some(self.resolve_input_value(value)?)), Some(value) => (value.pos, Some(self.resolve_input_value(value)?)),
None => (Pos::default(), None), None => (Pos::default(), None),
}; };
InputValueType::parse(value).map_err(|e| e.into_server_error().at(pos)) InputType::parse(value).map_err(|e| e.into_server_error().at(pos))
} }
/// Creates a uniform interface to inspect the forthcoming selections. /// Creates a uniform interface to inspect the forthcoming selections.

View File

@ -5,7 +5,7 @@ use std::marker::PhantomData;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
use crate::{parser, InputValueType, Pos, Value}; use crate::{parser, InputType, Pos, Value};
/// Extensions to the error. /// Extensions to the error.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
@ -117,7 +117,7 @@ pub struct InputValueError<T> {
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
impl<T: InputValueType> InputValueError<T> { impl<T: InputType> InputValueError<T> {
fn new(message: String) -> Self { fn new(message: String) -> Self {
Self { Self {
message, message,
@ -145,7 +145,7 @@ impl<T: InputValueType> InputValueError<T> {
} }
/// Propagate the error message to a different type. /// Propagate the error message to a different type.
pub fn propagate<U: InputValueType>(self) -> InputValueError<U> { pub fn propagate<U: InputType>(self) -> InputValueError<U> {
if T::type_name() != U::type_name() { if T::type_name() != U::type_name() {
InputValueError::new(format!( InputValueError::new(format!(
r#"{} (occurred while parsing "{}")"#, r#"{} (occurred while parsing "{}")"#,
@ -163,7 +163,7 @@ impl<T: InputValueType> InputValueError<T> {
} }
} }
impl<T: InputValueType, E: Display> From<E> for InputValueError<T> { impl<T: InputType, E: Display> From<E> for InputValueError<T> {
fn from(error: E) -> Self { fn from(error: E) -> Self {
Self::custom(error) Self::custom(error)
} }

View File

@ -69,6 +69,7 @@
//! - `chrono-tz`: Integrate with the [`chrono-tz` crate](https://crates.io/crates/chrono-tz). //! - `chrono-tz`: Integrate with the [`chrono-tz` crate](https://crates.io/crates/chrono-tz).
//! - `url`: Integrate with the [`url` crate](https://crates.io/crates/url). //! - `url`: Integrate with the [`url` crate](https://crates.io/crates/url).
//! - `uuid`: Integrate with the [`uuid` crate](https://crates.io/crates/uuid). //! - `uuid`: Integrate with the [`uuid` crate](https://crates.io/crates/uuid).
//! - `string_number`: Enable the [StringNumber](extensions/types.StringNumber.html).
//! //!
//! ## Integrations //! ## Integrations
//! //!
@ -199,8 +200,7 @@ pub use async_graphql_value::{
SerializerError, SerializerError,
}; };
pub use base::{ pub use base::{
Description, InputObjectType, InputValueType, InterfaceType, ObjectType, OutputValueType, Type, Description, InputObjectType, InputType, InterfaceType, ObjectType, OutputType, Type, UnionType,
UnionType,
}; };
pub use error::{ pub use error::{
Error, ErrorExtensionValues, ErrorExtensions, InputValueError, InputValueResult, Error, ErrorExtensionValues, ErrorExtensions, InputValueError, InputValueResult,

View File

@ -6,16 +6,15 @@ use crate::extensions::{ErrorLogger, ExtensionContext, ResolveInfo};
use crate::parser::types::Selection; use crate::parser::types::Selection;
use crate::registry::MetaType; use crate::registry::MetaType;
use crate::{ use crate::{
Context, ContextSelectionSet, Name, OutputValueType, PathSegment, ServerError, ServerResult, Context, ContextSelectionSet, Name, OutputType, PathSegment, ServerError, ServerResult, Value,
Value,
}; };
/// Represents a GraphQL container object. /// Represents a GraphQL container object.
/// ///
/// This helper trait allows the type to call `resolve_container` on itself in its /// This helper trait allows the type to call `resolve_container` on itself in its
/// `OutputValueType::resolve` implementation. /// `OutputType::resolve` implementation.
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait ContainerType: OutputValueType { pub trait ContainerType: OutputType {
/// This function returns true of type `EmptyMutation` only. /// This function returns true of type `EmptyMutation` only.
#[doc(hidden)] #[doc(hidden)]
fn is_empty() -> bool { fn is_empty() -> bool {

View File

@ -1,4 +1,4 @@
use crate::{InputValueError, InputValueResult, InputValueType, Name, Type, Value}; use crate::{InputType, InputValueError, InputValueResult, Name, Type, Value};
/// A variant of an enum. /// A variant of an enum.
pub struct EnumItem<T> { pub struct EnumItem<T> {
@ -16,8 +16,8 @@ pub trait EnumType: Type + Sized + Eq + Send + Copy + Sized + 'static {
/// Parse a value as an enum value. /// Parse a value as an enum value.
/// ///
/// This can be used to implement `InputValueType::parse`. /// This can be used to implement `InputType::parse`.
pub fn parse_enum<T: EnumType + InputValueType>(value: Value) -> InputValueResult<T> { pub fn parse_enum<T: EnumType + InputType>(value: Value) -> InputValueResult<T> {
let value = match &value { let value = match &value {
Value::Enum(s) => s, Value::Enum(s) => s,
Value::String(s) => s.as_str(), Value::String(s) => s.as_str(),
@ -38,7 +38,7 @@ pub fn parse_enum<T: EnumType + InputValueType>(value: Value) -> InputValueResul
/// Convert the enum value into a GraphQL value. /// Convert the enum value into a GraphQL value.
/// ///
/// This can be used to implement `InputValueType::to_value` or `OutputValueType::resolve`. /// This can be used to implement `InputType::to_value` or `OutputType::resolve`.
pub fn enum_value<T: EnumType>(value: T) -> Value { pub fn enum_value<T: EnumType>(value: T) -> Value {
let item = T::items().iter().find(|item| item.value == value).unwrap(); let item = T::items().iter().find(|item| item.value == value).unwrap();
Value::Enum(Name::new(item.name)) Value::Enum(Name::new(item.name))

View File

@ -1,11 +1,9 @@
use crate::extensions::{ErrorLogger, ExtensionContext, ResolveInfo}; use crate::extensions::{ErrorLogger, ExtensionContext, ResolveInfo};
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::{ use crate::{ContextSelectionSet, OutputType, PathSegment, Positioned, ServerResult, Type, Value};
ContextSelectionSet, OutputValueType, PathSegment, Positioned, ServerResult, Type, Value,
};
/// Resolve an list by executing each of the items concurrently. /// Resolve an list by executing each of the items concurrently.
pub async fn resolve_list<'a, T: OutputValueType + Send + Sync + 'a>( pub async fn resolve_list<'a, T: OutputType + Send + Sync + 'a>(
ctx: &ContextSelectionSet<'a>, ctx: &ContextSelectionSet<'a>,
field: &Positioned<Field>, field: &Positioned<Field>,
iter: impl IntoIterator<Item = T>, iter: impl IntoIterator<Item = T>,
@ -22,7 +20,7 @@ pub async fn resolve_list<'a, T: OutputValueType + Send + Sync + 'a>(
}; };
if ctx_idx.query_env.extensions.is_empty() { if ctx_idx.query_env.extensions.is_empty() {
OutputValueType::resolve(&item, &ctx_idx, field) OutputType::resolve(&item, &ctx_idx, field)
.await .await
.map_err(|e| e.path(PathSegment::Index(idx))) .map_err(|e| e.path(PathSegment::Index(idx)))
.log_error(&ctx_extension, &ctx_idx.query_env.extensions) .log_error(&ctx_extension, &ctx_idx.query_env.extensions)
@ -39,7 +37,7 @@ pub async fn resolve_list<'a, T: OutputValueType + Send + Sync + 'a>(
.extensions .extensions
.resolve_start(&ctx_extension, &resolve_info); .resolve_start(&ctx_extension, &resolve_info);
let res = OutputValueType::resolve(&item, &ctx_idx, field) let res = OutputType::resolve(&item, &ctx_idx, field)
.await .await
.map_err(|e| e.path(PathSegment::Index(idx))) .map_err(|e| e.path(PathSegment::Index(idx)))
.log_error(&ctx_extension, &ctx_idx.query_env.extensions)?; .log_error(&ctx_extension, &ctx_idx.query_env.extensions)?;

View File

@ -1,5 +1,5 @@
//! Utilities for implementing //! Utilities for implementing
//! [`OutputValueType::resolve`](trait.OutputValueType.html#tymethod.resolve). //! [`OutputType::resolve`](trait.OutputType.html#tymethod.resolve).
mod container; mod container;
mod r#enum; mod r#enum;

View File

@ -135,7 +135,7 @@ macro_rules! scalar_internal {
} }
} }
impl $crate::InputValueType for $ty { impl $crate::InputType for $ty {
fn parse( fn parse(
value: ::std::option::Option<$crate::Value>, value: ::std::option::Option<$crate::Value>,
) -> $crate::InputValueResult<Self> { ) -> $crate::InputValueResult<Self> {
@ -148,7 +148,7 @@ macro_rules! scalar_internal {
} }
#[$crate::async_trait::async_trait] #[$crate::async_trait::async_trait]
impl $crate::OutputValueType for $ty { impl $crate::OutputType for $ty {
async fn resolve( async fn resolve(
&self, &self,
_: &$crate::ContextSelectionSet<'_>, _: &$crate::ContextSelectionSet<'_>,

View File

@ -9,7 +9,7 @@ use crate::parser::types::Field;
use crate::resolver_utils::{resolve_container, ContainerType}; use crate::resolver_utils::{resolve_container, ContainerType};
use crate::types::connection::{CursorType, EmptyFields}; use crate::types::connection::{CursorType, EmptyFields};
use crate::{ use crate::{
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, Result, registry, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, Result,
ServerResult, Type, Value, ServerResult, Type, Value,
}; };
@ -122,7 +122,7 @@ impl<C, T, EC, EE> Connection<C, T, EC, EE> {
impl<C, T, EC, EE> Type for Connection<C, T, EC, EE> impl<C, T, EC, EE> Type for Connection<C, T, EC, EE>
where where
C: CursorType, C: CursorType,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
EC: ObjectType + Sync + Send, EC: ObjectType + Sync + Send,
EE: ObjectType + Sync + Send, EE: ObjectType + Sync + Send,
{ {
@ -194,7 +194,7 @@ where
impl<C, T, EC, EE> ContainerType for Connection<C, T, EC, EE> impl<C, T, EC, EE> ContainerType for Connection<C, T, EC, EE>
where where
C: CursorType + Send + Sync, C: CursorType + Send + Sync,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
EC: ObjectType + Sync + Send, EC: ObjectType + Sync + Send,
EE: ObjectType + Sync + Send, EE: ObjectType + Sync + Send,
{ {
@ -207,12 +207,12 @@ where
end_cursor: self.edges.last().map(|edge| edge.cursor.encode_cursor()), end_cursor: self.edges.last().map(|edge| edge.cursor.encode_cursor()),
}; };
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return OutputValueType::resolve(&page_info, &ctx_obj, ctx.item) return OutputType::resolve(&page_info, &ctx_obj, ctx.item)
.await .await
.map(Some); .map(Some);
} else if ctx.item.node.name.node == "edges" { } else if ctx.item.node.name.node == "edges" {
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return OutputValueType::resolve(&self.edges, &ctx_obj, ctx.item) return OutputType::resolve(&self.edges, &ctx_obj, ctx.item)
.await .await
.map(Some); .map(Some);
} }
@ -222,10 +222,10 @@ where
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<C, T, EC, EE> OutputValueType for Connection<C, T, EC, EE> impl<C, T, EC, EE> OutputType for Connection<C, T, EC, EE>
where where
C: CursorType + Send + Sync, C: CursorType + Send + Sync,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
EC: ObjectType + Sync + Send, EC: ObjectType + Sync + Send,
EE: ObjectType + Sync + Send, EE: ObjectType + Sync + Send,
{ {
@ -241,7 +241,7 @@ where
impl<C, T, EC, EE> ObjectType for Connection<C, T, EC, EE> impl<C, T, EC, EE> ObjectType for Connection<C, T, EC, EE>
where where
C: CursorType + Send + Sync, C: CursorType + Send + Sync,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
EC: ObjectType + Sync + Send, EC: ObjectType + Sync + Send,
EE: ObjectType + Sync + Send, EE: ObjectType + Sync + Send,
{ {

View File

@ -7,8 +7,8 @@ use crate::parser::types::Field;
use crate::resolver_utils::{resolve_container, ContainerType}; use crate::resolver_utils::{resolve_container, ContainerType};
use crate::types::connection::CursorType; use crate::types::connection::CursorType;
use crate::{ use crate::{
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, ServerResult, registry, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, ServerResult, Type,
Type, Value, Value,
}; };
/// The edge type output by the data source /// The edge type output by the data source
@ -43,7 +43,7 @@ impl<C: CursorType, T> Edge<C, T, EmptyFields> {
impl<C, T, E> Type for Edge<C, T, E> impl<C, T, E> Type for Edge<C, T, E>
where where
C: CursorType, C: CursorType,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
E: ObjectType + Sync + Send, E: ObjectType + Sync + Send,
{ {
fn type_name() -> Cow<'static, str> { fn type_name() -> Cow<'static, str> {
@ -111,13 +111,13 @@ where
impl<C, T, E> ContainerType for Edge<C, T, E> impl<C, T, E> ContainerType for Edge<C, T, E>
where where
C: CursorType + Send + Sync, C: CursorType + Send + Sync,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
E: ObjectType + Sync + Send, E: ObjectType + Sync + Send,
{ {
async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>> { async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>> {
if ctx.item.node.name.node == "node" { if ctx.item.node.name.node == "node" {
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return OutputValueType::resolve(&self.node, &ctx_obj, ctx.item) return OutputType::resolve(&self.node, &ctx_obj, ctx.item)
.await .await
.map(Some); .map(Some);
} else if ctx.item.node.name.node == "cursor" { } else if ctx.item.node.name.node == "cursor" {
@ -129,10 +129,10 @@ where
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<C, T, E> OutputValueType for Edge<C, T, E> impl<C, T, E> OutputType for Edge<C, T, E>
where where
C: CursorType + Send + Sync, C: CursorType + Send + Sync,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
E: ObjectType + Sync + Send, E: ObjectType + Sync + Send,
{ {
async fn resolve( async fn resolve(
@ -147,7 +147,7 @@ where
impl<C, T, E> ObjectType for Edge<C, T, E> impl<C, T, E> ObjectType for Edge<C, T, E>
where where
C: CursorType + Send + Sync, C: CursorType + Send + Sync,
T: OutputValueType + Send + Sync, T: OutputType + Send + Sync,
E: ObjectType + Sync + Send, E: ObjectType + Sync + Send,
{ {
} }

View File

@ -3,7 +3,7 @@ use std::borrow::Cow;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::ContainerType; use crate::resolver_utils::ContainerType;
use crate::{ use crate::{
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, ServerError, registry, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, ServerError,
ServerResult, Type, Value, ServerResult, Type, Value,
}; };
@ -60,7 +60,7 @@ impl ContainerType for EmptyMutation {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl OutputValueType for EmptyMutation { impl OutputType for EmptyMutation {
async fn resolve( async fn resolve(
&self, &self,
_ctx: &ContextSelectionSet<'_>, _ctx: &ContextSelectionSet<'_>,

View File

@ -1,8 +1,6 @@
use std::borrow::Cow; use std::borrow::Cow;
use crate::{ use crate::{registry, ContextSelectionSet, OutputType, Positioned, ServerResult, Type, Value};
registry, ContextSelectionSet, OutputValueType, Positioned, ServerResult, Type, Value,
};
use async_graphql_parser::types::Field; use async_graphql_parser::types::Field;
impl<'a, T> Type for Cow<'a, T> impl<'a, T> Type for Cow<'a, T>
@ -19,9 +17,9 @@ where
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<'a, T> OutputValueType for Cow<'a, T> impl<'a, T> OutputType for Cow<'a, T>
where where
T: OutputValueType + ToOwned + ?Sized + Send + Sync, T: OutputType + ToOwned + ?Sized + Send + Sync,
<T as ToOwned>::Owned: Send + Sync, <T as ToOwned>::Owned: Send + Sync,
{ {
async fn resolve( async fn resolve(

View File

@ -1,15 +1,14 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use crate::{ use crate::{
InputValueError, InputValueResult, InputValueType, Name, OutputValueType, Scalar, ScalarType, InputType, InputValueError, InputValueResult, Name, OutputType, Scalar, ScalarType, Value,
Value,
}; };
/// A scalar that can represent any JSON Object value. /// A scalar that can represent any JSON Object value.
#[Scalar(internal, name = "JSONObject")] #[Scalar(internal, name = "JSONObject")]
impl<T> ScalarType for BTreeMap<String, T> impl<T> ScalarType for BTreeMap<String, T>
where where
T: OutputValueType + InputValueType + Send + Sync, T: OutputType + InputType + Send + Sync,
{ {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -1,15 +1,14 @@
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
use crate::{ use crate::{
InputValueError, InputValueResult, InputValueType, Name, OutputValueType, Scalar, ScalarType, InputType, InputValueError, InputValueResult, Name, OutputType, Scalar, ScalarType, Value,
Value,
}; };
/// A scalar that can represent any JSON Object value. /// A scalar that can represent any JSON Object value.
#[Scalar(internal, name = "JSONObject")] #[Scalar(internal, name = "JSONObject")]
impl<T> ScalarType for HashMap<String, T> impl<T> ScalarType for HashMap<String, T>
where where
T: OutputValueType + InputValueType + Send + Sync, T: OutputType + InputType + Send + Sync,
{ {
fn parse(value: Value) -> InputValueResult<Self> { fn parse(value: Value) -> InputValueResult<Self> {
match value { match value {

View File

@ -4,8 +4,8 @@ use std::collections::BTreeSet;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::resolve_list; use crate::resolver_utils::resolve_list;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType, registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
OutputValueType, Positioned, ServerResult, Type, Value, Positioned, ServerResult, Type, Value,
}; };
impl<T: Type> Type for BTreeSet<T> { impl<T: Type> Type for BTreeSet<T> {
@ -23,31 +23,29 @@ impl<T: Type> Type for BTreeSet<T> {
} }
} }
impl<T: InputValueType + Ord> InputValueType for BTreeSet<T> { impl<T: InputType + Ord> InputType for BTreeSet<T> {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
match value.unwrap_or_default() { match value.unwrap_or_default() {
Value::List(values) => values Value::List(values) => values
.into_iter() .into_iter()
.map(|value| InputValueType::parse(Some(value))) .map(|value| InputType::parse(Some(value)))
.collect::<Result<_, _>>() .collect::<Result<_, _>>()
.map_err(InputValueError::propagate), .map_err(InputValueError::propagate),
value => Ok({ value => Ok({
let mut result = Self::default(); let mut result = Self::default();
result.insert( result.insert(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?,
);
result result
}), }),
} }
} }
fn to_value(&self) -> Value { fn to_value(&self) -> Value {
Value::List(self.iter().map(InputValueType::to_value).collect()) Value::List(self.iter().map(InputType::to_value).collect())
} }
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Send + Sync + Ord> OutputValueType for BTreeSet<T> { impl<T: OutputType + Send + Sync + Ord> OutputType for BTreeSet<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,

View File

@ -6,8 +6,8 @@ use std::hash::Hash;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::resolve_list; use crate::resolver_utils::resolve_list;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType, registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
OutputValueType, Positioned, Result, ServerResult, Type, Value, Positioned, Result, ServerResult, Type, Value,
}; };
impl<T: Type> Type for HashSet<T> { impl<T: Type> Type for HashSet<T> {
@ -25,31 +25,29 @@ impl<T: Type> Type for HashSet<T> {
} }
} }
impl<T: InputValueType + Hash + Eq> InputValueType for HashSet<T> { impl<T: InputType + Hash + Eq> InputType for HashSet<T> {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
match value.unwrap_or_default() { match value.unwrap_or_default() {
Value::List(values) => values Value::List(values) => values
.into_iter() .into_iter()
.map(|value| InputValueType::parse(Some(value))) .map(|value| InputType::parse(Some(value)))
.collect::<Result<_, _>>() .collect::<Result<_, _>>()
.map_err(InputValueError::propagate), .map_err(InputValueError::propagate),
value => Ok({ value => Ok({
let mut result = Self::default(); let mut result = Self::default();
result.insert( result.insert(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?,
);
result result
}), }),
} }
} }
fn to_value(&self) -> Value { fn to_value(&self) -> Value {
Value::List(self.iter().map(InputValueType::to_value).collect()) Value::List(self.iter().map(InputType::to_value).collect())
} }
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Send + Sync + Hash + Eq> OutputValueType for HashSet<T> { impl<T: OutputType + Send + Sync + Hash + Eq> OutputType for HashSet<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,

View File

@ -4,8 +4,8 @@ use std::collections::LinkedList;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::resolve_list; use crate::resolver_utils::resolve_list;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType, registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
OutputValueType, Positioned, ServerResult, Type, Value, Positioned, ServerResult, Type, Value,
}; };
impl<T: Type> Type for LinkedList<T> { impl<T: Type> Type for LinkedList<T> {
@ -23,31 +23,30 @@ impl<T: Type> Type for LinkedList<T> {
} }
} }
impl<T: InputValueType> InputValueType for LinkedList<T> { impl<T: InputType> InputType for LinkedList<T> {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
match value.unwrap_or_default() { match value.unwrap_or_default() {
Value::List(values) => values Value::List(values) => values
.into_iter() .into_iter()
.map(|value| InputValueType::parse(Some(value))) .map(|value| InputType::parse(Some(value)))
.collect::<Result<_, _>>() .collect::<Result<_, _>>()
.map_err(InputValueError::propagate), .map_err(InputValueError::propagate),
value => Ok({ value => Ok({
let mut result = Self::default(); let mut result = Self::default();
result.push_front( result
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?, .push_front(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
);
result result
}), }),
} }
} }
fn to_value(&self) -> Value { fn to_value(&self) -> Value {
Value::List(self.iter().map(InputValueType::to_value).collect()) Value::List(self.iter().map(InputType::to_value).collect())
} }
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Send + Sync> OutputValueType for LinkedList<T> { impl<T: OutputType + Send + Sync> OutputType for LinkedList<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,

View File

@ -2,9 +2,7 @@ use std::borrow::Cow;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::resolve_list; use crate::resolver_utils::resolve_list;
use crate::{ use crate::{registry, ContextSelectionSet, OutputType, Positioned, ServerResult, Type, Value};
registry, ContextSelectionSet, OutputValueType, Positioned, ServerResult, Type, Value,
};
impl<'a, T: Type + 'a> Type for &'a [T] { impl<'a, T: Type + 'a> Type for &'a [T] {
fn type_name() -> Cow<'static, str> { fn type_name() -> Cow<'static, str> {
@ -22,7 +20,7 @@ impl<'a, T: Type + 'a> Type for &'a [T] {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Send + Sync> OutputValueType for &[T] { impl<T: OutputType + Send + Sync> OutputType for &[T] {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,

View File

@ -3,8 +3,8 @@ use std::borrow::Cow;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::resolve_list; use crate::resolver_utils::resolve_list;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType, registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
OutputValueType, Positioned, Result, ServerResult, Type, Value, Positioned, Result, ServerResult, Type, Value,
}; };
impl<T: Type> Type for Vec<T> { impl<T: Type> Type for Vec<T> {
@ -22,27 +22,27 @@ impl<T: Type> Type for Vec<T> {
} }
} }
impl<T: InputValueType> InputValueType for Vec<T> { impl<T: InputType> InputType for Vec<T> {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
match value.unwrap_or_default() { match value.unwrap_or_default() {
Value::List(values) => values Value::List(values) => values
.into_iter() .into_iter()
.map(|value| InputValueType::parse(Some(value))) .map(|value| InputType::parse(Some(value)))
.collect::<Result<_, _>>() .collect::<Result<_, _>>()
.map_err(InputValueError::propagate), .map_err(InputValueError::propagate),
value => Ok(vec![ value => Ok(vec![
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)? InputType::parse(Some(value)).map_err(InputValueError::propagate)?
]), ]),
} }
} }
fn to_value(&self) -> Value { fn to_value(&self) -> Value {
Value::List(self.iter().map(InputValueType::to_value).collect()) Value::List(self.iter().map(InputType::to_value).collect())
} }
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Send + Sync> OutputValueType for Vec<T> { impl<T: OutputType + Send + Sync> OutputType for Vec<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,

View File

@ -4,8 +4,8 @@ use std::collections::VecDeque;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::resolve_list; use crate::resolver_utils::resolve_list;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType, registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
OutputValueType, Positioned, ServerResult, Type, Value, Positioned, ServerResult, Type, Value,
}; };
impl<T: Type> Type for VecDeque<T> { impl<T: Type> Type for VecDeque<T> {
@ -23,31 +23,30 @@ impl<T: Type> Type for VecDeque<T> {
} }
} }
impl<T: InputValueType> InputValueType for VecDeque<T> { impl<T: InputType> InputType for VecDeque<T> {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
match value.unwrap_or_default() { match value.unwrap_or_default() {
Value::List(values) => values Value::List(values) => values
.into_iter() .into_iter()
.map(|value| InputValueType::parse(Some(value))) .map(|value| InputType::parse(Some(value)))
.collect::<Result<_, _>>() .collect::<Result<_, _>>()
.map_err(InputValueError::propagate), .map_err(InputValueError::propagate),
value => Ok({ value => Ok({
let mut result = Self::default(); let mut result = Self::default();
result.push_back( result
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?, .push_back(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
);
result result
}), }),
} }
} }
fn to_value(&self) -> Value { fn to_value(&self) -> Value {
Value::List(self.iter().map(InputValueType::to_value).collect()) Value::List(self.iter().map(InputType::to_value).collect())
} }
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Send + Sync> OutputValueType for VecDeque<T> { impl<T: OutputType + Send + Sync> OutputType for VecDeque<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,

View File

@ -2,8 +2,8 @@ use std::borrow::Cow;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType, registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
OutputValueType, Positioned, ServerResult, Type, Value, Positioned, ServerResult, Type, Value,
}; };
impl<T: Type> Type for Option<T> { impl<T: Type> Type for Option<T> {
@ -21,7 +21,7 @@ impl<T: Type> Type for Option<T> {
} }
} }
impl<T: InputValueType> InputValueType for Option<T> { impl<T: InputType> InputType for Option<T> {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
match value.unwrap_or_default() { match value.unwrap_or_default() {
Value::Null => Ok(None), Value::Null => Ok(None),
@ -40,14 +40,14 @@ impl<T: InputValueType> InputValueType for Option<T> {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: OutputValueType + Sync> OutputValueType for Option<T> { impl<T: OutputType + Sync> OutputType for Option<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,
field: &Positioned<Field>, field: &Positioned<Field>,
) -> ServerResult<Value> { ) -> ServerResult<Value> {
if let Some(inner) = self { if let Some(inner) = self {
OutputValueType::resolve(inner, ctx, field).await OutputType::resolve(inner, ctx, field).await
} else { } else {
Ok(Value::Null) Ok(Value::Null)
} }

View File

@ -2,7 +2,7 @@ use std::borrow::Cow;
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::{ use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, OutputValueType, Positioned, registry, ContextSelectionSet, InputValueError, InputValueResult, OutputType, Positioned,
Scalar, ScalarType, ServerResult, Type, Value, Scalar, ScalarType, ServerResult, Type, Value,
}; };
@ -36,7 +36,7 @@ impl Type for str {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl OutputValueType for str { impl OutputType for str {
async fn resolve( async fn resolve(
&self, &self,
_: &ContextSelectionSet<'_>, _: &ContextSelectionSet<'_>,

View File

@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize};
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::registry::{MetaType, Registry}; use crate::registry::{MetaType, Registry};
use crate::{ use crate::{
from_value, to_value, ContextSelectionSet, InputValueResult, OutputValueType, Positioned, from_value, to_value, ContextSelectionSet, InputValueResult, OutputType, Positioned, Scalar,
Scalar, ScalarType, ServerResult, Type, Value, ScalarType, ServerResult, Type, Value,
}; };
/// A scalar that can represent any JSON value. /// A scalar that can represent any JSON value.
@ -50,7 +50,7 @@ impl<T: DeserializeOwned + Serialize + Send + Sync> ScalarType for Json<T> {
} }
} }
/// A `Json` type that only implements `OutputValueType`. /// A `Json` type that only implements `OutputType`.
#[derive(Serialize, Clone, Debug, Eq, PartialEq, Hash, Default)] #[derive(Serialize, Clone, Debug, Eq, PartialEq, Hash, Default)]
pub struct OutputJson<T>(pub T); pub struct OutputJson<T>(pub T);
@ -89,7 +89,7 @@ impl<T> Type for OutputJson<T> {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: Serialize + Send + Sync> OutputValueType for OutputJson<T> { impl<T: Serialize + Send + Sync> OutputType for OutputJson<T> {
async fn resolve( async fn resolve(
&self, &self,
_ctx: &ContextSelectionSet<'_>, _ctx: &ContextSelectionSet<'_>,

View File

@ -2,7 +2,7 @@ use std::borrow::Cow;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::{registry, InputValueError, InputValueResult, InputValueType, Type, Value}; use crate::{registry, InputType, InputValueError, InputValueResult, Type, Value};
/// Similar to `Option`, but it has three states, `undefined`, `null` and `x`. /// Similar to `Option`, but it has three states, `undefined`, `null` and `x`.
/// ///
@ -114,7 +114,7 @@ impl<T: Type> Type for MaybeUndefined<T> {
} }
} }
impl<T: InputValueType> InputValueType for MaybeUndefined<T> { impl<T: InputType> InputType for MaybeUndefined<T> {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
match value { match value {
None => Ok(MaybeUndefined::Undefined), None => Ok(MaybeUndefined::Undefined),

View File

@ -6,8 +6,8 @@ use crate::parser::types::Field;
use crate::registry::{MetaType, Registry}; use crate::registry::{MetaType, Registry};
use crate::resolver_utils::resolve_container; use crate::resolver_utils::resolve_container;
use crate::{ use crate::{
CacheControl, ContainerType, Context, ContextSelectionSet, ObjectType, OutputValueType, CacheControl, ContainerType, Context, ContextSelectionSet, ObjectType, OutputType, Positioned,
Positioned, ServerResult, SimpleObject, Type, Value, ServerResult, SimpleObject, Type, Value,
}; };
use async_graphql_value::ConstValue; use async_graphql_value::ConstValue;
@ -84,7 +84,7 @@ where
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<A, B> OutputValueType for MergedObject<A, B> impl<A, B> OutputType for MergedObject<A, B>
where where
A: ObjectType + Send + Sync, A: ObjectType + Send + Sync,
B: ObjectType + Send + Sync, B: ObjectType + Send + Sync,

View File

@ -6,8 +6,8 @@ use crate::model::{__Schema, __Type};
use crate::parser::types::Field; use crate::parser::types::Field;
use crate::resolver_utils::{resolve_container, ContainerType}; use crate::resolver_utils::{resolve_container, ContainerType};
use crate::{ use crate::{
registry, Any, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, registry, Any, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, ServerError,
ServerError, ServerResult, SimpleObject, Type, Value, ServerResult, SimpleObject, Type, Value,
}; };
/// Federation service /// Federation service
@ -89,7 +89,7 @@ impl<T: ObjectType + Send + Sync> ContainerType for QueryRoot<T> {
} }
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return OutputValueType::resolve( return OutputType::resolve(
&__Schema { &__Schema {
registry: &ctx.schema_env.registry, registry: &ctx.schema_env.registry,
}, },
@ -101,7 +101,7 @@ impl<T: ObjectType + Send + Sync> ContainerType for QueryRoot<T> {
} else if ctx.item.node.name.node == "__type" { } else if ctx.item.node.name.node == "__type" {
let type_name: String = ctx.param_value("name", None)?; let type_name: String = ctx.param_value("name", None)?;
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return OutputValueType::resolve( return OutputType::resolve(
&ctx.schema_env &ctx.schema_env
.registry .registry
.types .types
@ -126,7 +126,7 @@ impl<T: ObjectType + Send + Sync> ContainerType for QueryRoot<T> {
return Ok(Some(Value::List(res))); return Ok(Some(Value::List(res)));
} else if ctx.item.node.name.node == "_service" { } else if ctx.item.node.name.node == "_service" {
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set); let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
return OutputValueType::resolve( return OutputType::resolve(
&Service { &Service {
sdl: Some(ctx.schema_env.registry.export_sdl(true)), sdl: Some(ctx.schema_env.registry.export_sdl(true)),
}, },
@ -142,7 +142,7 @@ impl<T: ObjectType + Send + Sync> ContainerType for QueryRoot<T> {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: ObjectType + Send + Sync> OutputValueType for QueryRoot<T> { impl<T: ObjectType + Send + Sync> OutputType for QueryRoot<T> {
async fn resolve( async fn resolve(
&self, &self,
ctx: &ContextSelectionSet<'_>, ctx: &ContextSelectionSet<'_>,

View File

@ -5,7 +5,7 @@ use std::io::Read;
#[cfg(feature = "unblock")] #[cfg(feature = "unblock")]
use futures_util::io::AsyncRead; use futures_util::io::AsyncRead;
use crate::{registry, Context, InputValueError, InputValueResult, InputValueType, Type, Value}; use crate::{registry, Context, InputType, InputValueError, InputValueResult, Type, Value};
/// A file upload value. /// A file upload value.
pub struct UploadValue { pub struct UploadValue {
@ -114,7 +114,7 @@ impl Type for Upload {
} }
} }
impl InputValueType for Upload { impl InputType for Upload {
fn parse(value: Option<Value>) -> InputValueResult<Self> { fn parse(value: Option<Value>) -> InputValueResult<Self> {
const PREFIX: &str = "#__graphql_file__:"; const PREFIX: &str = "#__graphql_file__:";
let value = value.unwrap_or_default(); let value = value.unwrap_or_default();