pub use async_graphql_parser::{types::*, Pos, Positioned};
pub use graphql_toolkit_value::*;
pub trait IntoAst<T> {
#[must_use]
fn into_ast(self) -> T;
}
macro_rules! impl_into_ast {
($($ty:ty),* $(,)?) => {
$(
impl IntoAst<$ty> for $ty {
#[inline(always)]
fn into_ast(self) -> $ty {
self
}
}
)*
};
}
impl<S> IntoAst<Name> for S
where
S: AsRef<str>,
{
#[inline]
fn into_ast(self) -> Name {
Name::new(self)
}
}
impl_into_ast! {
BaseType, ConstValue, Directive, DocumentOperations, Field, FragmentDefinition, FragmentSpread,
InlineFragment, Number, OperationDefinition, OperationType, Selection, SelectionSet,
Type, TypeCondition, Value, VariableDefinition,
}
pub trait AstPositionExt: Sized {
#[must_use]
#[inline]
fn default_position(self) -> Positioned<Self> {
Positioned::new(self, Default::default())
}
#[must_use]
#[inline]
fn with_position(self, pos: Pos) -> Positioned<Self> {
Positioned::new(self, pos)
}
}
macro_rules! impl_ast_position_ext {
($($ty:ty),* $(,)?) => {
$(
impl AstPositionExt for $ty {}
)*
};
}
impl_ast_position_ext! {
BaseType, ConstValue, Directive, DocumentOperations, Field, FragmentDefinition, FragmentSpread,
InlineFragment, Name, Number, OperationDefinition, OperationType, Selection, SelectionSet,
Type, TypeCondition, Value, VariableDefinition,
}