Reworking base traits, vol.1 [skip ci]
This commit is contained in:
parent
97d2da581a
commit
8235ac22c0
19 changed files with 218 additions and 355 deletions
5
juniper/src/behavior.rs
Normal file
5
juniper/src/behavior.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
//! Default GraphQL behaviors.
|
||||
|
||||
/// Default standard behavior of GraphQL types implementation.
|
||||
#[derive(Debug)]
|
||||
pub enum Standard {}
|
|
@ -1,16 +1,10 @@
|
|||
pub mod resolve;
|
||||
|
||||
use crate::DefaultScalarValue;
|
||||
|
||||
pub use crate::{
|
||||
ast::InputValue, graphql_input_value as input_value, graphql_value as value, value::Value,
|
||||
};
|
||||
|
||||
pub use self::resolve::Type;
|
||||
|
||||
pub trait Interface<S = DefaultScalarValue>:
|
||||
pub trait Interface<S>:
|
||||
OutputType<S>
|
||||
+ Type<S>
|
||||
/*
|
||||
+ resolve::TypeName
|
||||
+ resolve::ConcreteTypeName
|
||||
+ resolve::Value<S>
|
||||
|
@ -19,51 +13,55 @@ pub trait Interface<S = DefaultScalarValue>:
|
|||
+ resolve::ConcreteValueAsync<S>
|
||||
+ resolve::Field<S>
|
||||
+ resolve::FieldAsync<S>
|
||||
|
||||
*/
|
||||
{
|
||||
fn assert_interface();
|
||||
}
|
||||
|
||||
pub trait Object<S = DefaultScalarValue>:
|
||||
pub trait Object<S>:
|
||||
OutputType<S>
|
||||
+ Type<S>
|
||||
/*
|
||||
+ resolve::TypeName
|
||||
+ resolve::ConcreteTypeName
|
||||
+ resolve::Value<S>
|
||||
+ resolve::ValueAsync<S>
|
||||
+ resolve::Field<S>
|
||||
+ resolve::FieldAsync<S>
|
||||
|
||||
*/
|
||||
{
|
||||
fn assert_object();
|
||||
}
|
||||
|
||||
pub trait Scalar<S = DefaultScalarValue>:
|
||||
InputType<S>
|
||||
+ OutputType<S>
|
||||
+ Type<S>
|
||||
+ resolve::TypeName
|
||||
+ resolve::Value<S>
|
||||
+ resolve::ValueAsync<S>
|
||||
pub trait Scalar<S>:
|
||||
OutputType<S> + /*
|
||||
resolve::TypeName + resolve::Value<S> + resolve::ValueAsync<S> */
|
||||
{
|
||||
fn assert_scalar();
|
||||
}
|
||||
|
||||
pub trait Union<S = DefaultScalarValue>:
|
||||
pub trait Union<S>:
|
||||
OutputType<S>
|
||||
+ Type<S>
|
||||
/*
|
||||
+ resolve::TypeName
|
||||
+ resolve::ConcreteTypeName
|
||||
+ resolve::Value<S>
|
||||
+ resolve::ValueAsync<S>
|
||||
+ resolve::ConcreteValue<S>
|
||||
+ resolve::ConcreteValueAsync<S>
|
||||
+ resolve::ConcreteValueAsync<S> */
|
||||
{
|
||||
fn assert_union();
|
||||
}
|
||||
|
||||
pub trait InputType<S = DefaultScalarValue> {
|
||||
pub trait InputType<'inp, Info: ?Sized, S: 'inp> /*:
|
||||
crate::resolve::Type<Info, S>
|
||||
+ crate::resolve::ToInputValue<S>
|
||||
+ crate::resolve::InputValue<'inp, S>*/
|
||||
{
|
||||
fn assert_input_type();
|
||||
}
|
||||
|
||||
pub trait OutputType<S = DefaultScalarValue> {
|
||||
pub trait OutputType<S>: /*Type<S>*/ {
|
||||
fn assert_output_type();
|
||||
}
|
||||
|
|
|
@ -1,230 +0,0 @@
|
|||
use crate::{
|
||||
meta::MetaType, resolve, Arguments, BoxFuture, DefaultScalarValue, ExecutionResult, Executor,
|
||||
Registry, Selection,
|
||||
};
|
||||
|
||||
pub trait Type<S = DefaultScalarValue> {
|
||||
fn meta<'r, Info: ?Sized>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S>
|
||||
where
|
||||
S: 'r,
|
||||
Self: resolve::Type<Info, S>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized, S> Type<S> for T {
|
||||
fn meta<'r, Info: ?Sized>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S>
|
||||
where
|
||||
S: 'r,
|
||||
Self: resolve::Type<Info, S>,
|
||||
{
|
||||
<Self as resolve::Type<Info, S>>::meta(registry, info)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TypeName {
|
||||
fn type_name<Info: ?Sized>(info: &Info) -> &str
|
||||
where
|
||||
Self: resolve::TypeName<Info>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized> TypeName for T {
|
||||
fn type_name<Info: ?Sized>(info: &Info) -> &str
|
||||
where
|
||||
Self: resolve::TypeName<Info>,
|
||||
{
|
||||
<Self as resolve::TypeName<Info>>::type_name(info)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ConcreteTypeName {
|
||||
fn concrete_type_name<'i, Info: ?Sized>(&self, info: &'i Info) -> &'i str
|
||||
where
|
||||
Self: resolve::ConcreteTypeName<Info>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized> ConcreteTypeName for T {
|
||||
fn concrete_type_name<'i, Info: ?Sized>(&self, info: &'i Info) -> &'i str
|
||||
where
|
||||
Self: resolve::ConcreteTypeName<Info>,
|
||||
{
|
||||
<Self as resolve::ConcreteTypeName<Info>>::concrete_type_name(self, info)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Value<S = DefaultScalarValue> {
|
||||
fn resolve_value<Info: ?Sized, Ctx: ?Sized>(
|
||||
&self,
|
||||
selection_set: Option<&[Selection<'_, S>]>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>
|
||||
where
|
||||
Self: resolve::Value<Info, Ctx, S>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized, S> Value<S> for T {
|
||||
fn resolve_value<Info: ?Sized, Ctx: ?Sized>(
|
||||
&self,
|
||||
selection_set: Option<&[Selection<'_, S>]>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>
|
||||
where
|
||||
Self: resolve::Value<Info, Ctx, S>,
|
||||
{
|
||||
<Self as resolve::Value<Info, Ctx, S>>::resolve_value(self, selection_set, info, executor)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ValueAsync<S = DefaultScalarValue> {
|
||||
fn resolve_value_async<'r, Info: ?Sized, Ctx: ?Sized>(
|
||||
&'r self,
|
||||
selection_set: Option<&'r [Selection<'_, S>]>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>
|
||||
where
|
||||
Self: resolve::ValueAsync<Info, Ctx, S>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized, S> ValueAsync<S> for T {
|
||||
fn resolve_value_async<'r, Info: ?Sized, Ctx: ?Sized>(
|
||||
&'r self,
|
||||
selection_set: Option<&'r [Selection<'_, S>]>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>
|
||||
where
|
||||
Self: resolve::ValueAsync<Info, Ctx, S>,
|
||||
{
|
||||
<Self as resolve::ValueAsync<Info, Ctx, S>>::resolve_value_async(
|
||||
self,
|
||||
selection_set,
|
||||
info,
|
||||
executor,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ConcreteValue<S = DefaultScalarValue> {
|
||||
fn resolve_concrete_value<Info: ?Sized, Ctx: ?Sized>(
|
||||
&self,
|
||||
type_name: &str,
|
||||
selection_set: Option<&[Selection<'_, S>]>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>
|
||||
where
|
||||
Self: resolve::ConcreteValue<Info, Ctx, S>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized, S> ConcreteValue<S> for T {
|
||||
fn resolve_concrete_value<Info: ?Sized, Ctx: ?Sized>(
|
||||
&self,
|
||||
type_name: &str,
|
||||
selection_set: Option<&[Selection<'_, S>]>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>
|
||||
where
|
||||
Self: resolve::ConcreteValue<Info, Ctx, S>,
|
||||
{
|
||||
<Self as resolve::ConcreteValue<Info, Ctx, S>>::resolve_concrete_value(
|
||||
self,
|
||||
type_name,
|
||||
selection_set,
|
||||
info,
|
||||
executor,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ConcreteValueAsync<S = DefaultScalarValue> {
|
||||
fn resolve_concrete_value_async<'r, Info: ?Sized, Ctx: ?Sized>(
|
||||
&'r self,
|
||||
type_name: &str,
|
||||
selection_set: Option<&'r [Selection<'_, S>]>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>
|
||||
where
|
||||
Self: resolve::ConcreteValueAsync<Info, Ctx, S>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized, S> ConcreteValueAsync<S> for T {
|
||||
fn resolve_concrete_value_async<'r, Info: ?Sized, Ctx: ?Sized>(
|
||||
&'r self,
|
||||
type_name: &str,
|
||||
selection_set: Option<&'r [Selection<'_, S>]>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>
|
||||
where
|
||||
Self: resolve::ConcreteValueAsync<Info, Ctx, S>,
|
||||
{
|
||||
<Self as resolve::ConcreteValueAsync<Info, Ctx, S>>::resolve_concrete_value_async(
|
||||
self,
|
||||
type_name,
|
||||
selection_set,
|
||||
info,
|
||||
executor,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Field<S = DefaultScalarValue> {
|
||||
fn resolve_field<Info: ?Sized, Ctx: ?Sized>(
|
||||
&self,
|
||||
field_name: &str,
|
||||
arguments: &Arguments<S>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>
|
||||
where
|
||||
Self: resolve::Field<Info, Ctx, S>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized, S> Field<S> for T {
|
||||
fn resolve_field<Info: ?Sized, Ctx: ?Sized>(
|
||||
&self,
|
||||
field_name: &str,
|
||||
arguments: &Arguments<S>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>
|
||||
where
|
||||
Self: resolve::Field<Info, Ctx, S>,
|
||||
{
|
||||
<Self as resolve::Field<Info, Ctx, S>>::resolve_field(
|
||||
self, field_name, arguments, info, executor,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FieldAsync<S = DefaultScalarValue> {
|
||||
fn resolve_field_async<'r, Info: ?Sized, Ctx: ?Sized>(
|
||||
&'r self,
|
||||
field_name: &'r str,
|
||||
arguments: &'r Arguments<S>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>
|
||||
where
|
||||
Self: resolve::FieldAsync<Info, Ctx, S>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized, S> FieldAsync<S> for T {
|
||||
fn resolve_field_async<'r, Info: ?Sized, Ctx: ?Sized>(
|
||||
&'r self,
|
||||
field_name: &'r str,
|
||||
arguments: &'r Arguments<S>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>
|
||||
where
|
||||
Self: resolve::FieldAsync<Info, Ctx, S>,
|
||||
{
|
||||
<Self as resolve::FieldAsync<Info, Ctx, S>>::resolve_field_async(
|
||||
self, field_name, arguments, info, executor,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ pub use juniper_codegen::{
|
|||
pub mod macros;
|
||||
|
||||
mod ast;
|
||||
pub mod behavior;
|
||||
pub mod executor;
|
||||
pub mod graphql;
|
||||
pub mod http;
|
||||
|
|
|
@ -2,22 +2,10 @@
|
|||
|
||||
use futures::future::BoxFuture;
|
||||
|
||||
use crate::{Arguments as FieldArguments, ExecutionResult, Executor, GraphQLValue, ScalarValue};
|
||||
|
||||
/// Alias for a [GraphQL object][1], [scalar][2] or [interface][3] type's name
|
||||
/// in a GraphQL schema.
|
||||
///
|
||||
/// See [`BaseType`] for more info.
|
||||
///
|
||||
/// [1]: https://spec.graphql.org/October2021#sec-Objects
|
||||
/// [2]: https://spec.graphql.org/October2021#sec-Scalars
|
||||
/// [3]: https://spec.graphql.org/October2021#sec-Interfaces
|
||||
pub type Type = &'static str;
|
||||
|
||||
/// Alias for a slice of [`Type`]s.
|
||||
///
|
||||
/// See [`BaseSubTypes`] for more info.
|
||||
pub type Types = &'static [Type];
|
||||
use crate::{
|
||||
reflect::{Type, Types, WrappedValue},
|
||||
Arguments as FieldArguments, ExecutionResult, Executor, GraphQLValue, ScalarValue,
|
||||
};
|
||||
|
||||
/// Naming of a [GraphQL object][1], [scalar][2] or [interface][3] [`Type`].
|
||||
///
|
||||
|
@ -69,9 +57,6 @@ where
|
|||
const NAMES: Types = T::NAMES;
|
||||
}
|
||||
|
||||
/// Alias for a value of a [`WrappedType`] (composed GraphQL type).
|
||||
pub type WrappedValue = u128;
|
||||
|
||||
// TODO: Just use `&str`s once they're allowed in `const` generics.
|
||||
/// Encoding of a composed GraphQL type in numbers.
|
||||
///
|
||||
|
|
|
@ -1 +1,54 @@
|
|||
pub use crate::macros::reflect::*;
|
||||
//! Compile-time reflection of Rust types into GraphQL types.
|
||||
|
||||
use crate::behavior;
|
||||
|
||||
/// Alias for a [GraphQL type][0]'s name in a GraphQL schema.
|
||||
///
|
||||
/// See [`BaseType`] for more info.
|
||||
///
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Types
|
||||
pub type Type = &'static str;
|
||||
|
||||
/// Alias for a slice of [`Type`]s.
|
||||
///
|
||||
/// See [`BaseSubTypes`] for more info.
|
||||
pub type Types = &'static [Type];
|
||||
|
||||
/// Basic reflection of a [GraphQL type][0].
|
||||
///
|
||||
/// This trait is transparent to [`Option`], [`Vec`] and other containers, so to
|
||||
/// fully represent a [GraphQL object][1] we additionally use [`WrappedType`].
|
||||
///
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Types
|
||||
pub trait BaseType<Behavior: ?Sized = behavior::Standard> {
|
||||
/// [`Type`] of this [GraphQL type][0].
|
||||
///
|
||||
/// Different Rust types may have the same [`NAME`]. For example, [`String`]
|
||||
/// and [`&str`](prim@str) share the `String!` GraphQL [`Type`].
|
||||
///
|
||||
/// [`NAME`]: Self::NAME
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Types
|
||||
const NAME: Type;
|
||||
}
|
||||
|
||||
/// Reflection of [sub-types][2] of a [GraphQL type][0].
|
||||
///
|
||||
/// This trait is transparent to [`Option`], [`Vec`] and other containers.
|
||||
///
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Types
|
||||
/// [2]: https://spec.graphql.org/October2021#sel-JAHZhCHCDEJDAAAEEFDBtzC
|
||||
pub trait BaseSubTypes<Behavior: ?Sized = behavior::Standard> {
|
||||
/// Sub-[`Types`] of this [GraphQL type][0].
|
||||
///
|
||||
/// Contains [at least][2] the [`BaseType::NAME`] of this [GraphQL type][0].
|
||||
///
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Types
|
||||
/// [2]: https://spec.graphql.org/October2021#sel-JAHZhCHCDEJDAAAEEFDBtzC
|
||||
const NAMES: Types;
|
||||
}
|
||||
|
||||
/// Alias for a value of a [`WrappedType`] (composed
|
||||
/// [GraphQL wrapping type][0]).
|
||||
///
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Wrapping-Types
|
||||
pub type WrappedValue = u128;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use crate::{
|
||||
graphql,
|
||||
behavior, graphql,
|
||||
meta::MetaType,
|
||||
parser::{self, ParseError},
|
||||
Arguments, BoxFuture, DefaultScalarValue, ExecutionResult, Executor, IntoFieldError, Registry,
|
||||
Selection,
|
||||
Arguments, BoxFuture, ExecutionResult, Executor, IntoFieldError, Registry, Selection,
|
||||
};
|
||||
|
||||
#[doc(inline)]
|
||||
|
@ -12,96 +11,136 @@ pub use crate::types::{
|
|||
r#ref::TryFromInputValue as InputValueAsRef, rc::TryFromInputValue as InputValueAsRc,
|
||||
};
|
||||
|
||||
pub trait Type<Info: ?Sized, S = DefaultScalarValue> {
|
||||
fn meta<'r>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S>
|
||||
pub trait Type<TypeInfo: ?Sized, ScalarValue, Behavior: ?Sized = behavior::Standard> {
|
||||
fn meta<'r>(
|
||||
registry: &mut Registry<'r, ScalarValue>,
|
||||
type_info: &TypeInfo,
|
||||
) -> MetaType<'r, ScalarValue>
|
||||
where
|
||||
S: 'r; // TODO: remove?
|
||||
ScalarValue: 'r; // TODO: remove?
|
||||
}
|
||||
|
||||
pub trait TypeName<Info: ?Sized> {
|
||||
fn type_name(info: &Info) -> &str;
|
||||
pub trait TypeName<TypeInfo: ?Sized, Behavior: ?Sized = behavior::Standard> {
|
||||
fn type_name(type_info: &TypeInfo) -> &str;
|
||||
}
|
||||
|
||||
pub trait ConcreteTypeName<Info: ?Sized> {
|
||||
fn concrete_type_name<'i>(&self, info: &'i Info) -> &'i str;
|
||||
pub trait ConcreteTypeName<TypeInfo: ?Sized> {
|
||||
fn concrete_type_name<'i>(&self, type_info: &'i TypeInfo) -> &'i str;
|
||||
}
|
||||
|
||||
pub trait Value<Info: ?Sized, Ctx: ?Sized, S = DefaultScalarValue> {
|
||||
pub trait Value<
|
||||
TypeInfo: ?Sized,
|
||||
Context: ?Sized,
|
||||
ScalarValue,
|
||||
Behavior: ?Sized = behavior::Standard,
|
||||
>
|
||||
{
|
||||
fn resolve_value(
|
||||
&self,
|
||||
selection_set: Option<&[Selection<'_, S>]>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>;
|
||||
selection_set: Option<&[Selection<'_, ScalarValue>]>,
|
||||
type_info: &TypeInfo,
|
||||
executor: &Executor<Context, ScalarValue>,
|
||||
) -> ExecutionResult<ScalarValue>;
|
||||
}
|
||||
|
||||
pub trait ValueAsync<Info: ?Sized, Ctx: ?Sized, S = DefaultScalarValue> {
|
||||
pub trait ValueAsync<
|
||||
TypeInfo: ?Sized,
|
||||
Context: ?Sized,
|
||||
ScalarValue,
|
||||
Behavior: ?Sized = behavior::Standard,
|
||||
>
|
||||
{
|
||||
fn resolve_value_async<'r>(
|
||||
&'r self,
|
||||
selection_set: Option<&'r [Selection<'_, S>]>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>;
|
||||
selection_set: Option<&'r [Selection<'_, ScalarValue>]>,
|
||||
type_info: &'r TypeInfo,
|
||||
executor: &'r Executor<Context, ScalarValue>,
|
||||
) -> BoxFuture<'r, ExecutionResult<ScalarValue>>;
|
||||
}
|
||||
|
||||
pub trait ConcreteValue<Info: ?Sized, Ctx: ?Sized, S = DefaultScalarValue> {
|
||||
pub trait ConcreteValue<
|
||||
TypeInfo: ?Sized,
|
||||
Context: ?Sized,
|
||||
ScalarValue,
|
||||
Behavior: ?Sized = behavior::Standard,
|
||||
>
|
||||
{
|
||||
fn resolve_concrete_value(
|
||||
&self,
|
||||
type_name: &str,
|
||||
selection_set: Option<&[Selection<'_, S>]>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>;
|
||||
selection_set: Option<&[Selection<'_, ScalarValue>]>,
|
||||
type_info: &TypeInfo,
|
||||
executor: &Executor<Context, ScalarValue>,
|
||||
) -> ExecutionResult<ScalarValue>;
|
||||
}
|
||||
|
||||
pub trait ConcreteValueAsync<Info: ?Sized, Ctx: ?Sized, S = DefaultScalarValue> {
|
||||
pub trait ConcreteValueAsync<TypeInfo: ?Sized, Context: ?Sized, ScalarValue> {
|
||||
fn resolve_concrete_value_async<'r>(
|
||||
&'r self,
|
||||
type_name: &str,
|
||||
selection_set: Option<&'r [Selection<'_, S>]>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>;
|
||||
selection_set: Option<&'r [Selection<'_, ScalarValue>]>,
|
||||
type_info: &'r TypeInfo,
|
||||
executor: &'r Executor<Context, ScalarValue>,
|
||||
) -> BoxFuture<'r, ExecutionResult<ScalarValue>>;
|
||||
}
|
||||
|
||||
pub trait Field<Info: ?Sized, Ctx: ?Sized, S = DefaultScalarValue> {
|
||||
pub trait Field<
|
||||
TypeInfo: ?Sized,
|
||||
Context: ?Sized,
|
||||
ScalarValue,
|
||||
Behavior: ?Sized = behavior::Standard,
|
||||
>
|
||||
{
|
||||
fn resolve_field(
|
||||
&self,
|
||||
field_name: &str,
|
||||
arguments: &Arguments<S>,
|
||||
info: &Info,
|
||||
executor: &Executor<Ctx, S>,
|
||||
) -> ExecutionResult<S>;
|
||||
arguments: &Arguments<ScalarValue>,
|
||||
type_info: &TypeInfo,
|
||||
executor: &Executor<Context, ScalarValue>,
|
||||
) -> ExecutionResult<ScalarValue>;
|
||||
}
|
||||
|
||||
pub trait FieldAsync<Info: ?Sized, Ctx: ?Sized, S = DefaultScalarValue> {
|
||||
pub trait FieldAsync<
|
||||
TypeInfo: ?Sized,
|
||||
Context: ?Sized,
|
||||
ScalarValue,
|
||||
Behavior: ?Sized = behavior::Standard,
|
||||
>
|
||||
{
|
||||
fn resolve_field_async<'r>(
|
||||
&'r self,
|
||||
field_name: &'r str,
|
||||
arguments: &'r Arguments<S>,
|
||||
info: &'r Info,
|
||||
executor: &'r Executor<Ctx, S>,
|
||||
) -> BoxFuture<'r, ExecutionResult<S>>;
|
||||
arguments: &'r Arguments<ScalarValue>,
|
||||
type_info: &'r TypeInfo,
|
||||
executor: &'r Executor<Context, ScalarValue>,
|
||||
) -> BoxFuture<'r, ExecutionResult<ScalarValue>>;
|
||||
}
|
||||
|
||||
pub trait ScalarToken<S = DefaultScalarValue> {
|
||||
fn parse_scalar_token(token: parser::ScalarToken<'_>) -> Result<S, ParseError<'_>>;
|
||||
pub trait ToInputValue<ScalarValue, Behavior: ?Sized = behavior::Standard> {
|
||||
fn to_input_value(&self) -> graphql::InputValue<ScalarValue>;
|
||||
}
|
||||
|
||||
pub trait InputValue<'input, S: 'input = DefaultScalarValue>: Sized {
|
||||
type Error: IntoFieldError<S>;
|
||||
pub trait InputValue<'input, ScalarValue: 'input, Behavior: ?Sized = behavior::Standard>:
|
||||
Sized
|
||||
{
|
||||
type Error: IntoFieldError<ScalarValue>;
|
||||
|
||||
fn try_from_input_value(v: &'input graphql::InputValue<S>) -> Result<Self, Self::Error>;
|
||||
fn try_from_input_value(
|
||||
v: &'input graphql::InputValue<ScalarValue>,
|
||||
) -> Result<Self, Self::Error>;
|
||||
|
||||
fn try_from_implicit_null() -> Result<Self, Self::Error> {
|
||||
Self::try_from_input_value(&graphql::InputValue::<S>::Null)
|
||||
Self::try_from_input_value(&graphql::InputValue::<ScalarValue>::Null)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait InputValueOwned<S = DefaultScalarValue>: for<'i> InputValue<'i, S> {}
|
||||
|
||||
impl<T, S> InputValueOwned<S> for T where T: for<'i> InputValue<'i, S> {}
|
||||
|
||||
pub trait ToInputValue<S> {
|
||||
fn to_input_value(&self) -> graphql::InputValue<S>;
|
||||
pub trait InputValueOwned<ScalarValue, Behavior: ?Sized = behavior::Standard>:
|
||||
for<'i> InputValue<'i, ScalarValue, Behavior>
|
||||
{
|
||||
}
|
||||
|
||||
impl<T, S, B: ?Sized> InputValueOwned<S, B> for T where T: for<'i> InputValue<'i, S, B> {}
|
||||
|
||||
pub trait ScalarToken<ScalarValue, Behavior: ?Sized = behavior::Standard> {
|
||||
fn parse_scalar_token(token: parser::ScalarToken<'_>) -> Result<ScalarValue, ParseError<'_>>;
|
||||
}
|
||||
|
|
|
@ -203,9 +203,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S> graphql::InputType<S> for Arc<T>
|
||||
impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Arc<T>
|
||||
where
|
||||
T: graphql::InputType<S> + ?Sized,
|
||||
T: graphql::InputType<'i, Info, S> + ?Sized,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
|
|
|
@ -73,14 +73,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S, const N: usize> graphql::InputType<S> for [T; N]
|
||||
/*
|
||||
impl<'i, T, Info, S, const N: usize> graphql::InputType<'i, Info, S> for [T; N]
|
||||
where
|
||||
T: graphql::InputType<S>,
|
||||
T: graphql::InputType<'i, Info, S>,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl<T, S, const N: usize> graphql::OutputType<S> for [T; N]
|
||||
where
|
||||
|
|
|
@ -201,9 +201,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S> graphql::InputType<S> for Box<T>
|
||||
impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Box<T>
|
||||
where
|
||||
T: graphql::InputType<S> + ?Sized,
|
||||
T: graphql::InputType<'i, Info, S> + resolve::InputValueAsBox<'i, S> + ?Sized,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
|
|
|
@ -355,9 +355,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S> graphql::InputType<S> for Nullable<T>
|
||||
impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Nullable<T>
|
||||
where
|
||||
T: graphql::InputType<S>,
|
||||
T: graphql::InputType<'i, Info, S>,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
|
|
|
@ -88,9 +88,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S> graphql::InputType<S> for Option<T>
|
||||
impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Option<T>
|
||||
where
|
||||
T: graphql::InputType<S>,
|
||||
T: graphql::InputType<'i, Info, S>,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
|
|
|
@ -203,9 +203,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S> graphql::InputType<S> for Rc<T>
|
||||
impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Rc<T>
|
||||
where
|
||||
T: graphql::InputType<S> + ?Sized,
|
||||
T: graphql::InputType<'i, Info, S> + ?Sized,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
|
|
|
@ -189,14 +189,16 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'me, T, S> graphql::InputType<S> for &'me T
|
||||
/*
|
||||
impl<'me, 'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for &'me T
|
||||
where
|
||||
T: graphql::InputType<S> + ?Sized,
|
||||
Self: resolve::Type<Info, S> + resolve::ToInputValue<S> + resolve::InputValue<'i, S>,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
impl<'me, T, S> graphql::OutputType<S> for &'me T
|
||||
where
|
||||
|
|
|
@ -160,15 +160,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'me, T, S> graphql::InputType<S> for &'me mut T
|
||||
where
|
||||
T: graphql::InputType<S> + ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'me, T, S> graphql::OutputType<S> for &'me mut T
|
||||
where
|
||||
T: graphql::OutputType<S> + ?Sized,
|
||||
|
|
|
@ -71,6 +71,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl<T, S> graphql::InputType<S> for [T]
|
||||
where
|
||||
T: graphql::InputType<S>,
|
||||
|
@ -79,6 +80,7 @@ where
|
|||
T::assert_input_type()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl<T, S> graphql::OutputType<S> for [T]
|
||||
where
|
||||
|
|
|
@ -117,9 +117,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> graphql::InputType<S> for str {
|
||||
/*
|
||||
impl<'i, Info, S: 'i> graphql::InputType<'i, Info, S> for str
|
||||
where
|
||||
Self: resolve::Type<Info, S> + resolve::ToInputValue<S> + resolve::InputValue<'i, S>,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {}
|
||||
}
|
||||
*/
|
||||
|
||||
impl<S> graphql::OutputType<S> for str {
|
||||
fn assert_output_type() {}
|
||||
|
|
|
@ -69,14 +69,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S> graphql::InputType<S> for Vec<T>
|
||||
/*
|
||||
impl<'i, T, Info, S> graphql::InputType<'i, Info, S> for Vec<T>
|
||||
where
|
||||
T: graphql::InputType<S>,
|
||||
T: graphql::InputType<'i, Info, S>,
|
||||
Info: ?Sized,
|
||||
{
|
||||
fn assert_input_type() {
|
||||
T::assert_input_type()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl<T, S> graphql::OutputType<S> for Vec<T>
|
||||
where
|
||||
|
|
|
@ -337,8 +337,8 @@ impl ToTokens for Definition {
|
|||
self.impl_resolve_to_input_value().to_tokens(into);
|
||||
self.impl_resolve_input_value().to_tokens(into);
|
||||
self.impl_resolve_scalar_token().to_tokens(into);
|
||||
self.impl_input_and_output_type().to_tokens(into);
|
||||
//self.impl_scalar().to_tokens(into);
|
||||
//self.impl_graphql_input_and_output_type().to_tokens(into);
|
||||
//self.impl_graphql_scalar().to_tokens(into);
|
||||
self.impl_reflect().to_tokens(into);
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ impl Definition {
|
|||
/// [`graphql::OutputType`]: juniper::graphql::OutputType
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Scalars
|
||||
#[must_use]
|
||||
fn impl_input_and_output_type(&self) -> TokenStream {
|
||||
fn impl_graphql_input_and_output_type(&self) -> TokenStream {
|
||||
let (ty, generics) = self.ty_and_generics();
|
||||
let (sv, generics) = self.mix_scalar_value(generics);
|
||||
let (impl_gens, _, where_clause) = generics.split_for_impl();
|
||||
|
@ -403,7 +403,7 @@ impl Definition {
|
|||
/// [`graphql::Scalar`]: juniper::graphql::Scalar
|
||||
/// [0]: https://spec.graphql.org/October2021#sec-Scalars
|
||||
#[must_use]
|
||||
fn impl_scalar(&self) -> TokenStream {
|
||||
fn impl_graphql_scalar(&self) -> TokenStream {
|
||||
let (ty, generics) = self.ty_and_generics();
|
||||
let (sv, generics) = self.mix_scalar_value(generics);
|
||||
let (impl_gens, _, where_clause) = generics.split_for_impl();
|
||||
|
|
Loading…
Add table
Reference in a new issue