Rename InputValueType to InputType and OutputValueType to OutputType.
This commit is contained in:
parent
d39a2f55a9
commit
03f6ed4ba2
|
@ -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
|
||||
we will execute just one.
|
||||
|
||||
At the core of all the resolver logic there are two traits: `InputValueType` and `OutputValueType`
|
||||
which represent a GraphQL input value and GraphQL output value respectively. `InputValueType` just
|
||||
requires conversions to and from `async_graphql::Value`. `OutputValueType` is an async trait with a
|
||||
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. `InputType` just
|
||||
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
|
||||
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
|
||||
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.
|
||||
|
|
|
@ -149,7 +149,7 @@ pub fn generate(enum_args: &args::Enum) -> GeneratorResult<TokenStream> {
|
|||
}
|
||||
|
||||
#[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> {
|
||||
#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]
|
||||
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> {
|
||||
::std::result::Result::Ok(#crate_name::resolver_utils::enum_value(*self))
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
|
|||
});
|
||||
|
||||
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)))
|
||||
).map_err(#crate_name::InputValueError::propagate)?;
|
||||
});
|
||||
|
@ -82,7 +82,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
|
|||
fields.push(ident);
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
@ -105,7 +105,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
|
|||
.map(|value| {
|
||||
quote! {
|
||||
::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 = {
|
||||
match obj.get(#name) {
|
||||
::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)?
|
||||
},
|
||||
::std::option::Option::None => #default,
|
||||
|
@ -127,7 +127,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
|
|||
} else {
|
||||
get_fields.push(quote! {
|
||||
#[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)?;
|
||||
});
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
|
|||
put_fields.push(quote! {
|
||||
map.insert(
|
||||
#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)]
|
||||
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> {
|
||||
if let ::std::option::Option::Some(#crate_name::Value::Object(obj)) = value {
|
||||
#(#get_fields)*
|
||||
|
|
|
@ -210,7 +210,7 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
|
|||
.map(|value| {
|
||||
quote! {
|
||||
::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 {
|
||||
#(#get_params)*
|
||||
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)]
|
||||
#[#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> {
|
||||
#crate_name::resolver_utils::resolve_container(ctx, self).await
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
|
|||
|
||||
#[allow(clippy::all, clippy::pedantic)]
|
||||
#[#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> {
|
||||
#crate_name::resolver_utils::resolve_container(ctx, self).await
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ pub fn generate(
|
|||
{
|
||||
return Err(Error::new_spanned(
|
||||
arg,
|
||||
"Only types that implement `InputValueType` can be used as input arguments.",
|
||||
"Only types that implement `InputType` can be used as input arguments.",
|
||||
)
|
||||
.into());
|
||||
} else {
|
||||
|
@ -152,7 +152,7 @@ pub fn generate(
|
|||
});
|
||||
key_getter.push(quote! {
|
||||
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
|
||||
})
|
||||
});
|
||||
|
@ -161,7 +161,7 @@ pub fn generate(
|
|||
} else {
|
||||
// requires
|
||||
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))?;
|
||||
});
|
||||
use_keys.push(ident);
|
||||
|
@ -197,7 +197,7 @@ pub fn generate(
|
|||
if let (#(#key_pat),*) = (#(#key_getter),*) {
|
||||
#(#requires_getter)*
|
||||
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(
|
||||
arg,
|
||||
"Only types that implement `InputValueType` can be used as input arguments.",
|
||||
"Only types that implement `InputType` can be used as input arguments.",
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ pub fn generate(
|
|||
.map(|value| {
|
||||
quote! {
|
||||
::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
|
||||
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
|
||||
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)]
|
||||
#[#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> {
|
||||
#crate_name::resolver_utils::resolve_container(ctx, self).await
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ pub fn generate(
|
|||
}
|
||||
|
||||
#[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> {
|
||||
<#self_ty as #crate_name::ScalarType>::parse(value.unwrap_or_default())
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ pub fn generate(
|
|||
|
||||
#[allow(clippy::all, clippy::pedantic)]
|
||||
#[#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(
|
||||
&self,
|
||||
_: &#crate_name::ContextSelectionSet<'_>,
|
||||
|
|
|
@ -124,7 +124,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
|
|||
#guard
|
||||
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);
|
||||
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)]
|
||||
#[#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> {
|
||||
#crate_name::resolver_utils::resolve_container(ctx, self).await
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ pub fn generate(
|
|||
{
|
||||
return Err(Error::new_spanned(
|
||||
arg,
|
||||
"Only types that implement `InputValueType` can be used as input arguments.",
|
||||
"Only types that implement `InputType` can be used as input arguments.",
|
||||
)
|
||||
.into());
|
||||
} else {
|
||||
|
@ -177,7 +177,7 @@ pub fn generate(
|
|||
.map(|value| {
|
||||
quote! {
|
||||
::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);
|
||||
|
||||
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.execution_end(&ctx_extension);
|
||||
|
|
|
@ -197,7 +197,7 @@ pub fn generate(union_args: &args::Union) -> GeneratorResult<TokenStream> {
|
|||
|
||||
#[allow(clippy::all, clippy::pedantic)]
|
||||
#[#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> {
|
||||
#crate_name::resolver_utils::resolve_container(ctx, self).await
|
||||
}
|
||||
|
|
10
src/base.rs
10
src/base.rs
|
@ -36,7 +36,7 @@ pub trait Type {
|
|||
}
|
||||
|
||||
/// Represents a GraphQL input value.
|
||||
pub trait InputValueType: Type + Sized {
|
||||
pub trait InputType: Type + Sized {
|
||||
/// Parse from `Value`. None represents undefined.
|
||||
fn parse(value: Option<Value>) -> InputValueResult<Self>;
|
||||
|
||||
|
@ -46,7 +46,7 @@ pub trait InputValueType: Type + Sized {
|
|||
|
||||
/// Represents a GraphQL output value.
|
||||
#[async_trait::async_trait]
|
||||
pub trait OutputValueType: Type {
|
||||
pub trait OutputType: Type {
|
||||
/// Resolve an output value to `async_graphql::Value`.
|
||||
async fn resolve(
|
||||
&self,
|
||||
|
@ -66,7 +66,7 @@ impl<T: Type + Send + Sync + ?Sized> Type for &T {
|
|||
}
|
||||
|
||||
#[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)]
|
||||
async fn resolve(
|
||||
&self,
|
||||
|
@ -92,7 +92,7 @@ impl<T: Type> Type for Result<T> {
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<T: OutputValueType + Sync> OutputValueType for Result<T> {
|
||||
impl<T: OutputType + Sync> OutputType for Result<T> {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
@ -118,4 +118,4 @@ pub trait InterfaceType: ContainerType {}
|
|||
pub trait UnionType: ContainerType {}
|
||||
|
||||
/// A GraphQL input object.
|
||||
pub trait InputObjectType: InputValueType {}
|
||||
pub trait InputObjectType: InputType {}
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::parser::types::{
|
|||
};
|
||||
use crate::schema::SchemaEnv;
|
||||
use crate::{
|
||||
Error, InputValueType, Lookahead, Name, Pos, Positioned, Result, ServerError, ServerResult,
|
||||
Error, InputType, Lookahead, Name, Pos, Positioned, Result, ServerError, ServerResult,
|
||||
UploadValue, Value,
|
||||
};
|
||||
|
||||
|
@ -493,7 +493,7 @@ impl<'a, T> ContextBase<'a, T> {
|
|||
let condition_input = self.resolve_input_value(condition_input)?;
|
||||
|
||||
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))?
|
||||
{
|
||||
return Ok(true);
|
||||
|
@ -523,7 +523,7 @@ impl<'a> ContextBase<'a, &'a Positioned<SelectionSet>> {
|
|||
|
||||
impl<'a> ContextBase<'a, &'a Positioned<Field>> {
|
||||
#[doc(hidden)]
|
||||
pub fn param_value<T: InputValueType>(
|
||||
pub fn param_value<T: InputType>(
|
||||
&self,
|
||||
name: &str,
|
||||
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)?)),
|
||||
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.
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::marker::PhantomData;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{parser, InputValueType, Pos, Value};
|
||||
use crate::{parser, InputType, Pos, Value};
|
||||
|
||||
/// Extensions to the error.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
|
@ -117,7 +117,7 @@ pub struct InputValueError<T> {
|
|||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: InputValueType> InputValueError<T> {
|
||||
impl<T: InputType> InputValueError<T> {
|
||||
fn new(message: String) -> Self {
|
||||
Self {
|
||||
message,
|
||||
|
@ -145,7 +145,7 @@ impl<T: InputValueType> InputValueError<T> {
|
|||
}
|
||||
|
||||
/// 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() {
|
||||
InputValueError::new(format!(
|
||||
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 {
|
||||
Self::custom(error)
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
//! - `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).
|
||||
//! - `uuid`: Integrate with the [`uuid` crate](https://crates.io/crates/uuid).
|
||||
//! - `string_number`: Enable the [StringNumber](extensions/types.StringNumber.html).
|
||||
//!
|
||||
//! ## Integrations
|
||||
//!
|
||||
|
@ -199,8 +200,7 @@ pub use async_graphql_value::{
|
|||
SerializerError,
|
||||
};
|
||||
pub use base::{
|
||||
Description, InputObjectType, InputValueType, InterfaceType, ObjectType, OutputValueType, Type,
|
||||
UnionType,
|
||||
Description, InputObjectType, InputType, InterfaceType, ObjectType, OutputType, Type, UnionType,
|
||||
};
|
||||
pub use error::{
|
||||
Error, ErrorExtensionValues, ErrorExtensions, InputValueError, InputValueResult,
|
||||
|
|
|
@ -6,16 +6,15 @@ use crate::extensions::{ErrorLogger, ExtensionContext, ResolveInfo};
|
|||
use crate::parser::types::Selection;
|
||||
use crate::registry::MetaType;
|
||||
use crate::{
|
||||
Context, ContextSelectionSet, Name, OutputValueType, PathSegment, ServerError, ServerResult,
|
||||
Value,
|
||||
Context, ContextSelectionSet, Name, OutputType, PathSegment, ServerError, ServerResult, Value,
|
||||
};
|
||||
|
||||
/// Represents a GraphQL container object.
|
||||
///
|
||||
/// This helper trait allows the type to call `resolve_container` on itself in its
|
||||
/// `OutputValueType::resolve` implementation.
|
||||
/// `OutputType::resolve` implementation.
|
||||
#[async_trait::async_trait]
|
||||
pub trait ContainerType: OutputValueType {
|
||||
pub trait ContainerType: OutputType {
|
||||
/// This function returns true of type `EmptyMutation` only.
|
||||
#[doc(hidden)]
|
||||
fn is_empty() -> bool {
|
||||
|
|
|
@ -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.
|
||||
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.
|
||||
///
|
||||
/// This can be used to implement `InputValueType::parse`.
|
||||
pub fn parse_enum<T: EnumType + InputValueType>(value: Value) -> InputValueResult<T> {
|
||||
/// This can be used to implement `InputType::parse`.
|
||||
pub fn parse_enum<T: EnumType + InputType>(value: Value) -> InputValueResult<T> {
|
||||
let value = match &value {
|
||||
Value::Enum(s) => s,
|
||||
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.
|
||||
///
|
||||
/// 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 {
|
||||
let item = T::items().iter().find(|item| item.value == value).unwrap();
|
||||
Value::Enum(Name::new(item.name))
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
use crate::extensions::{ErrorLogger, ExtensionContext, ResolveInfo};
|
||||
use crate::parser::types::Field;
|
||||
use crate::{
|
||||
ContextSelectionSet, OutputValueType, PathSegment, Positioned, ServerResult, Type, Value,
|
||||
};
|
||||
use crate::{ContextSelectionSet, OutputType, PathSegment, Positioned, ServerResult, Type, Value};
|
||||
|
||||
/// 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>,
|
||||
field: &Positioned<Field>,
|
||||
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() {
|
||||
OutputValueType::resolve(&item, &ctx_idx, field)
|
||||
OutputType::resolve(&item, &ctx_idx, field)
|
||||
.await
|
||||
.map_err(|e| e.path(PathSegment::Index(idx)))
|
||||
.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
|
||||
.resolve_start(&ctx_extension, &resolve_info);
|
||||
|
||||
let res = OutputValueType::resolve(&item, &ctx_idx, field)
|
||||
let res = OutputType::resolve(&item, &ctx_idx, field)
|
||||
.await
|
||||
.map_err(|e| e.path(PathSegment::Index(idx)))
|
||||
.log_error(&ctx_extension, &ctx_idx.query_env.extensions)?;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//! Utilities for implementing
|
||||
//! [`OutputValueType::resolve`](trait.OutputValueType.html#tymethod.resolve).
|
||||
//! [`OutputType::resolve`](trait.OutputType.html#tymethod.resolve).
|
||||
|
||||
mod container;
|
||||
mod r#enum;
|
||||
|
|
|
@ -135,7 +135,7 @@ macro_rules! scalar_internal {
|
|||
}
|
||||
}
|
||||
|
||||
impl $crate::InputValueType for $ty {
|
||||
impl $crate::InputType for $ty {
|
||||
fn parse(
|
||||
value: ::std::option::Option<$crate::Value>,
|
||||
) -> $crate::InputValueResult<Self> {
|
||||
|
@ -148,7 +148,7 @@ macro_rules! scalar_internal {
|
|||
}
|
||||
|
||||
#[$crate::async_trait::async_trait]
|
||||
impl $crate::OutputValueType for $ty {
|
||||
impl $crate::OutputType for $ty {
|
||||
async fn resolve(
|
||||
&self,
|
||||
_: &$crate::ContextSelectionSet<'_>,
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::parser::types::Field;
|
|||
use crate::resolver_utils::{resolve_container, ContainerType};
|
||||
use crate::types::connection::{CursorType, EmptyFields};
|
||||
use crate::{
|
||||
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, Result,
|
||||
registry, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, Result,
|
||||
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>
|
||||
where
|
||||
C: CursorType,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
EC: ObjectType + Sync + Send,
|
||||
EE: ObjectType + Sync + Send,
|
||||
{
|
||||
|
@ -194,7 +194,7 @@ where
|
|||
impl<C, T, EC, EE> ContainerType for Connection<C, T, EC, EE>
|
||||
where
|
||||
C: CursorType + Send + Sync,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
EC: ObjectType + Sync + Send,
|
||||
EE: ObjectType + Sync + Send,
|
||||
{
|
||||
|
@ -207,12 +207,12 @@ where
|
|||
end_cursor: self.edges.last().map(|edge| edge.cursor.encode_cursor()),
|
||||
};
|
||||
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
|
||||
.map(Some);
|
||||
} else if ctx.item.node.name.node == "edges" {
|
||||
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
|
||||
.map(Some);
|
||||
}
|
||||
|
@ -222,10 +222,10 @@ where
|
|||
}
|
||||
|
||||
#[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
|
||||
C: CursorType + Send + Sync,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
EC: ObjectType + Sync + Send,
|
||||
EE: ObjectType + Sync + Send,
|
||||
{
|
||||
|
@ -241,7 +241,7 @@ where
|
|||
impl<C, T, EC, EE> ObjectType for Connection<C, T, EC, EE>
|
||||
where
|
||||
C: CursorType + Send + Sync,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
EC: ObjectType + Sync + Send,
|
||||
EE: ObjectType + Sync + Send,
|
||||
{
|
||||
|
|
|
@ -7,8 +7,8 @@ use crate::parser::types::Field;
|
|||
use crate::resolver_utils::{resolve_container, ContainerType};
|
||||
use crate::types::connection::CursorType;
|
||||
use crate::{
|
||||
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, ServerResult,
|
||||
Type, Value,
|
||||
registry, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, ServerResult, Type,
|
||||
Value,
|
||||
};
|
||||
|
||||
/// 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>
|
||||
where
|
||||
C: CursorType,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
E: ObjectType + Sync + Send,
|
||||
{
|
||||
fn type_name() -> Cow<'static, str> {
|
||||
|
@ -111,13 +111,13 @@ where
|
|||
impl<C, T, E> ContainerType for Edge<C, T, E>
|
||||
where
|
||||
C: CursorType + Send + Sync,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
E: ObjectType + Sync + Send,
|
||||
{
|
||||
async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>> {
|
||||
if ctx.item.node.name.node == "node" {
|
||||
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
|
||||
.map(Some);
|
||||
} else if ctx.item.node.name.node == "cursor" {
|
||||
|
@ -129,10 +129,10 @@ where
|
|||
}
|
||||
|
||||
#[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
|
||||
C: CursorType + Send + Sync,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
E: ObjectType + Sync + Send,
|
||||
{
|
||||
async fn resolve(
|
||||
|
@ -147,7 +147,7 @@ where
|
|||
impl<C, T, E> ObjectType for Edge<C, T, E>
|
||||
where
|
||||
C: CursorType + Send + Sync,
|
||||
T: OutputValueType + Send + Sync,
|
||||
T: OutputType + Send + Sync,
|
||||
E: ObjectType + Sync + Send,
|
||||
{
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::borrow::Cow;
|
|||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::ContainerType;
|
||||
use crate::{
|
||||
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, ServerError,
|
||||
registry, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, ServerError,
|
||||
ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
|
@ -60,7 +60,7 @@ impl ContainerType for EmptyMutation {
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl OutputValueType for EmptyMutation {
|
||||
impl OutputType for EmptyMutation {
|
||||
async fn resolve(
|
||||
&self,
|
||||
_ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, OutputValueType, Positioned, ServerResult, Type, Value,
|
||||
};
|
||||
use crate::{registry, ContextSelectionSet, OutputType, Positioned, ServerResult, Type, Value};
|
||||
use async_graphql_parser::types::Field;
|
||||
|
||||
impl<'a, T> Type for Cow<'a, T>
|
||||
|
@ -19,9 +17,9 @@ where
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<'a, T> OutputValueType for Cow<'a, T>
|
||||
impl<'a, T> OutputType for Cow<'a, T>
|
||||
where
|
||||
T: OutputValueType + ToOwned + ?Sized + Send + Sync,
|
||||
T: OutputType + ToOwned + ?Sized + Send + Sync,
|
||||
<T as ToOwned>::Owned: Send + Sync,
|
||||
{
|
||||
async fn resolve(
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::{
|
||||
InputValueError, InputValueResult, InputValueType, Name, OutputValueType, Scalar, ScalarType,
|
||||
Value,
|
||||
InputType, InputValueError, InputValueResult, Name, OutputType, Scalar, ScalarType, Value,
|
||||
};
|
||||
|
||||
/// A scalar that can represent any JSON Object value.
|
||||
#[Scalar(internal, name = "JSONObject")]
|
||||
impl<T> ScalarType for BTreeMap<String, T>
|
||||
where
|
||||
T: OutputValueType + InputValueType + Send + Sync,
|
||||
T: OutputType + InputType + Send + Sync,
|
||||
{
|
||||
fn parse(value: Value) -> InputValueResult<Self> {
|
||||
match value {
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use crate::{
|
||||
InputValueError, InputValueResult, InputValueType, Name, OutputValueType, Scalar, ScalarType,
|
||||
Value,
|
||||
InputType, InputValueError, InputValueResult, Name, OutputType, Scalar, ScalarType, Value,
|
||||
};
|
||||
|
||||
/// A scalar that can represent any JSON Object value.
|
||||
#[Scalar(internal, name = "JSONObject")]
|
||||
impl<T> ScalarType for HashMap<String, T>
|
||||
where
|
||||
T: OutputValueType + InputValueType + Send + Sync,
|
||||
T: OutputType + InputType + Send + Sync,
|
||||
{
|
||||
fn parse(value: Value) -> InputValueResult<Self> {
|
||||
match value {
|
||||
|
|
|
@ -4,8 +4,8 @@ use std::collections::BTreeSet;
|
|||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::resolve_list;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
|
||||
OutputValueType, Positioned, ServerResult, Type, Value,
|
||||
registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
|
||||
Positioned, ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
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> {
|
||||
match value.unwrap_or_default() {
|
||||
Value::List(values) => values
|
||||
.into_iter()
|
||||
.map(|value| InputValueType::parse(Some(value)))
|
||||
.map(|value| InputType::parse(Some(value)))
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(InputValueError::propagate),
|
||||
value => Ok({
|
||||
let mut result = Self::default();
|
||||
result.insert(
|
||||
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?,
|
||||
);
|
||||
result.insert(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
|
||||
result
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
impl<T: OutputValueType + Send + Sync + Ord> OutputValueType for BTreeSet<T> {
|
||||
impl<T: OutputType + Send + Sync + Ord> OutputType for BTreeSet<T> {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -6,8 +6,8 @@ use std::hash::Hash;
|
|||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::resolve_list;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
|
||||
OutputValueType, Positioned, Result, ServerResult, Type, Value,
|
||||
registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
|
||||
Positioned, Result, ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
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> {
|
||||
match value.unwrap_or_default() {
|
||||
Value::List(values) => values
|
||||
.into_iter()
|
||||
.map(|value| InputValueType::parse(Some(value)))
|
||||
.map(|value| InputType::parse(Some(value)))
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(InputValueError::propagate),
|
||||
value => Ok({
|
||||
let mut result = Self::default();
|
||||
result.insert(
|
||||
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?,
|
||||
);
|
||||
result.insert(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
|
||||
result
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
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(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -4,8 +4,8 @@ use std::collections::LinkedList;
|
|||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::resolve_list;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
|
||||
OutputValueType, Positioned, ServerResult, Type, Value,
|
||||
registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
|
||||
Positioned, ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
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> {
|
||||
match value.unwrap_or_default() {
|
||||
Value::List(values) => values
|
||||
.into_iter()
|
||||
.map(|value| InputValueType::parse(Some(value)))
|
||||
.map(|value| InputType::parse(Some(value)))
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(InputValueError::propagate),
|
||||
value => Ok({
|
||||
let mut result = Self::default();
|
||||
result.push_front(
|
||||
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?,
|
||||
);
|
||||
result
|
||||
.push_front(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
|
||||
result
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
impl<T: OutputValueType + Send + Sync> OutputValueType for LinkedList<T> {
|
||||
impl<T: OutputType + Send + Sync> OutputType for LinkedList<T> {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -2,9 +2,7 @@ use std::borrow::Cow;
|
|||
|
||||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::resolve_list;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, OutputValueType, Positioned, ServerResult, Type, Value,
|
||||
};
|
||||
use crate::{registry, ContextSelectionSet, OutputType, Positioned, ServerResult, Type, Value};
|
||||
|
||||
impl<'a, T: Type + 'a> Type for &'a [T] {
|
||||
fn type_name() -> Cow<'static, str> {
|
||||
|
@ -22,7 +20,7 @@ impl<'a, T: Type + 'a> Type for &'a [T] {
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<T: OutputValueType + Send + Sync> OutputValueType for &[T] {
|
||||
impl<T: OutputType + Send + Sync> OutputType for &[T] {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -3,8 +3,8 @@ use std::borrow::Cow;
|
|||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::resolve_list;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
|
||||
OutputValueType, Positioned, Result, ServerResult, Type, Value,
|
||||
registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
|
||||
Positioned, Result, ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
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> {
|
||||
match value.unwrap_or_default() {
|
||||
Value::List(values) => values
|
||||
.into_iter()
|
||||
.map(|value| InputValueType::parse(Some(value)))
|
||||
.map(|value| InputType::parse(Some(value)))
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(InputValueError::propagate),
|
||||
value => Ok(vec![
|
||||
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?
|
||||
InputType::parse(Some(value)).map_err(InputValueError::propagate)?
|
||||
]),
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
impl<T: OutputValueType + Send + Sync> OutputValueType for Vec<T> {
|
||||
impl<T: OutputType + Send + Sync> OutputType for Vec<T> {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -4,8 +4,8 @@ use std::collections::VecDeque;
|
|||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::resolve_list;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
|
||||
OutputValueType, Positioned, ServerResult, Type, Value,
|
||||
registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
|
||||
Positioned, ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
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> {
|
||||
match value.unwrap_or_default() {
|
||||
Value::List(values) => values
|
||||
.into_iter()
|
||||
.map(|value| InputValueType::parse(Some(value)))
|
||||
.map(|value| InputType::parse(Some(value)))
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(InputValueError::propagate),
|
||||
value => Ok({
|
||||
let mut result = Self::default();
|
||||
result.push_back(
|
||||
InputValueType::parse(Some(value)).map_err(InputValueError::propagate)?,
|
||||
);
|
||||
result
|
||||
.push_back(InputType::parse(Some(value)).map_err(InputValueError::propagate)?);
|
||||
result
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
impl<T: OutputValueType + Send + Sync> OutputValueType for VecDeque<T> {
|
||||
impl<T: OutputType + Send + Sync> OutputType for VecDeque<T> {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -2,8 +2,8 @@ use std::borrow::Cow;
|
|||
|
||||
use crate::parser::types::Field;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
|
||||
OutputValueType, Positioned, ServerResult, Type, Value,
|
||||
registry, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType,
|
||||
Positioned, ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
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> {
|
||||
match value.unwrap_or_default() {
|
||||
Value::Null => Ok(None),
|
||||
|
@ -40,14 +40,14 @@ impl<T: InputValueType> InputValueType for Option<T> {
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<T: OutputValueType + Sync> OutputValueType for Option<T> {
|
||||
impl<T: OutputType + Sync> OutputType for Option<T> {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
field: &Positioned<Field>,
|
||||
) -> ServerResult<Value> {
|
||||
if let Some(inner) = self {
|
||||
OutputValueType::resolve(inner, ctx, field).await
|
||||
OutputType::resolve(inner, ctx, field).await
|
||||
} else {
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::borrow::Cow;
|
|||
|
||||
use crate::parser::types::Field;
|
||||
use crate::{
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, OutputValueType, Positioned,
|
||||
registry, ContextSelectionSet, InputValueError, InputValueResult, OutputType, Positioned,
|
||||
Scalar, ScalarType, ServerResult, Type, Value,
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,7 @@ impl Type for str {
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl OutputValueType for str {
|
||||
impl OutputType for str {
|
||||
async fn resolve(
|
||||
&self,
|
||||
_: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::parser::types::Field;
|
||||
use crate::registry::{MetaType, Registry};
|
||||
use crate::{
|
||||
from_value, to_value, ContextSelectionSet, InputValueResult, OutputValueType, Positioned,
|
||||
Scalar, ScalarType, ServerResult, Type, Value,
|
||||
from_value, to_value, ContextSelectionSet, InputValueResult, OutputType, Positioned, Scalar,
|
||||
ScalarType, ServerResult, Type, 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)]
|
||||
pub struct OutputJson<T>(pub T);
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl<T> Type for OutputJson<T> {
|
|||
}
|
||||
|
||||
#[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(
|
||||
&self,
|
||||
_ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::borrow::Cow;
|
|||
|
||||
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`.
|
||||
///
|
||||
|
@ -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> {
|
||||
match value {
|
||||
None => Ok(MaybeUndefined::Undefined),
|
||||
|
|
|
@ -6,8 +6,8 @@ use crate::parser::types::Field;
|
|||
use crate::registry::{MetaType, Registry};
|
||||
use crate::resolver_utils::resolve_container;
|
||||
use crate::{
|
||||
CacheControl, ContainerType, Context, ContextSelectionSet, ObjectType, OutputValueType,
|
||||
Positioned, ServerResult, SimpleObject, Type, Value,
|
||||
CacheControl, ContainerType, Context, ContextSelectionSet, ObjectType, OutputType, Positioned,
|
||||
ServerResult, SimpleObject, Type, Value,
|
||||
};
|
||||
use async_graphql_value::ConstValue;
|
||||
|
||||
|
@ -84,7 +84,7 @@ where
|
|||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<A, B> OutputValueType for MergedObject<A, B>
|
||||
impl<A, B> OutputType for MergedObject<A, B>
|
||||
where
|
||||
A: ObjectType + Send + Sync,
|
||||
B: ObjectType + Send + Sync,
|
||||
|
|
|
@ -6,8 +6,8 @@ use crate::model::{__Schema, __Type};
|
|||
use crate::parser::types::Field;
|
||||
use crate::resolver_utils::{resolve_container, ContainerType};
|
||||
use crate::{
|
||||
registry, Any, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned,
|
||||
ServerError, ServerResult, SimpleObject, Type, Value,
|
||||
registry, Any, Context, ContextSelectionSet, ObjectType, OutputType, Positioned, ServerError,
|
||||
ServerResult, SimpleObject, Type, Value,
|
||||
};
|
||||
|
||||
/// 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);
|
||||
return OutputValueType::resolve(
|
||||
return OutputType::resolve(
|
||||
&__Schema {
|
||||
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" {
|
||||
let type_name: String = ctx.param_value("name", None)?;
|
||||
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
|
||||
return OutputValueType::resolve(
|
||||
return OutputType::resolve(
|
||||
&ctx.schema_env
|
||||
.registry
|
||||
.types
|
||||
|
@ -126,7 +126,7 @@ impl<T: ObjectType + Send + Sync> ContainerType for QueryRoot<T> {
|
|||
return Ok(Some(Value::List(res)));
|
||||
} else if ctx.item.node.name.node == "_service" {
|
||||
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
|
||||
return OutputValueType::resolve(
|
||||
return OutputType::resolve(
|
||||
&Service {
|
||||
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]
|
||||
impl<T: ObjectType + Send + Sync> OutputValueType for QueryRoot<T> {
|
||||
impl<T: ObjectType + Send + Sync> OutputType for QueryRoot<T> {
|
||||
async fn resolve(
|
||||
&self,
|
||||
ctx: &ContextSelectionSet<'_>,
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::io::Read;
|
|||
#[cfg(feature = "unblock")]
|
||||
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.
|
||||
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> {
|
||||
const PREFIX: &str = "#__graphql_file__:";
|
||||
let value = value.unwrap_or_default();
|
||||
|
|
Loading…
Reference in New Issue