Add a basic lookahead functionality

This commit is contained in:
Georg Semmler 2018-01-26 15:03:29 +01:00 committed by Magnus Hallin
parent 61f0c7d337
commit dd99914fbe
4 changed files with 1129 additions and 1 deletions

File diff suppressed because it is too large Load diff

View file

@ -19,6 +19,10 @@ use schema::model::{RootNode, SchemaType, TypeType};
use types::base::GraphQLType; use types::base::GraphQLType;
use types::name::Name; use types::name::Name;
mod look_ahead;
pub use self::look_ahead::{Applies, LookAheadArgument, LookAheadSelection, LookAheadValue, LookAheadMethods, ChildSelection};
/// A type registry used to build schemas /// A type registry used to build schemas
/// ///
/// The registry gathers metadata for all types in a schema. It provides /// The registry gathers metadata for all types in a schema. It provides
@ -51,6 +55,7 @@ where
context: &'a CtxT, context: &'a CtxT,
errors: &'a RwLock<Vec<ExecutionError>>, errors: &'a RwLock<Vec<ExecutionError>>,
field_path: FieldPath<'a>, field_path: FieldPath<'a>,
type_name: &'a str,
} }
/// Error type for errors that occur during query execution /// Error type for errors that occur during query execution
@ -319,6 +324,7 @@ impl<'a, CtxT> Executor<'a, CtxT> {
context: ctx, context: ctx,
errors: self.errors, errors: self.errors,
field_path: self.field_path.clone(), field_path: self.field_path.clone(),
type_name: self.type_name,
} }
} }
@ -345,6 +351,7 @@ impl<'a, CtxT> Executor<'a, CtxT> {
context: self.context, context: self.context,
errors: self.errors, errors: self.errors,
field_path: FieldPath::Field(field_alias, location, &self.field_path), field_path: FieldPath::Field(field_alias, location, &self.field_path),
type_name: self.type_name
} }
} }
@ -366,6 +373,7 @@ impl<'a, CtxT> Executor<'a, CtxT> {
context: self.context, context: self.context,
errors: self.errors, errors: self.errors,
field_path: self.field_path.clone(), field_path: self.field_path.clone(),
type_name: type_name.unwrap(),
} }
} }
@ -421,6 +429,18 @@ impl<'a, CtxT> Executor<'a, CtxT> {
error: error, error: error,
}); });
} }
pub fn look_ahead(&self) -> LookAheadSelection {
LookAheadSelection{
name: self.type_name,
alias: None,
arguments: Vec::new(),
childs: self.current_selection_set.map(|s| s.iter().map(|s| ChildSelection {
inner: LookAheadSelection::build_from_selection(s, self.variables, self.fragments),
applies_for: Applies::All
}).collect()).unwrap_or_else(Vec::new)
}
}
} }
impl<'a> FieldPath<'a> { impl<'a> FieldPath<'a> {
@ -553,6 +573,7 @@ where
context: context, context: context,
errors: &errors, errors: &errors,
field_path: FieldPath::Root(op.start), field_path: FieldPath::Root(op.start),
type_name: &op.item.name.map(|n| n.item).unwrap_or(""),
}; };
value = match op.item.operation_type { value = match op.item.operation_type {

View file

@ -153,6 +153,7 @@ use validation::{validate_input_values, visit_all_rules, ValidatorContext};
pub use ast::{FromInputValue, InputValue, Selection, ToInputValue, Type}; pub use ast::{FromInputValue, InputValue, Selection, ToInputValue, Type};
pub use executor::{Context, ExecutionError, ExecutionResult, Executor, FieldError, FieldResult, pub use executor::{Context, ExecutionError, ExecutionResult, Executor, FieldError, FieldResult,
FromContext, IntoResolvable, Registry, Variables}; FromContext, IntoResolvable, Registry, Variables};
pub use executor::{Applies, LookAheadArgument, LookAheadSelection, LookAheadValue, LookAheadMethods};
pub use schema::model::RootNode; pub use schema::model::RootNode;
pub use types::base::{Arguments, GraphQLType, TypeKind}; pub use types::base::{Arguments, GraphQLType, TypeKind};
pub use types::scalars::{EmptyMutation, ID}; pub use types::scalars::{EmptyMutation, ID};

View file

@ -13,7 +13,7 @@ use parser::Spanning;
/// values or variables. Also, lists and objects do not contain any location /// values or variables. Also, lists and objects do not contain any location
/// information since they are generated by resolving fields and values rather /// information since they are generated by resolving fields and values rather
/// than parsing a source query. /// than parsing a source query.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Clone)]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum Value { pub enum Value {
Null, Null,