Use borrowed names when constructing Type instances
This commit is contained in:
parent
1f62b628f9
commit
f066fca1f4
27 changed files with 504 additions and 469 deletions
34
src/ast.rs
34
src/ast.rs
|
@ -13,19 +13,19 @@ use parser::Spanning;
|
|||
/// This enum carries no semantic information and might refer to types that do
|
||||
/// not exist.
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
pub enum Type {
|
||||
pub enum Type<'a> {
|
||||
/// A nullable named type, e.g. `String`
|
||||
Named(String),
|
||||
Named(&'a str),
|
||||
/// A nullable list type, e.g. `[String]`
|
||||
///
|
||||
/// The list itself is what's nullable, the containing type might be non-null.
|
||||
List(Box<Type>),
|
||||
List(Box<Type<'a>>),
|
||||
/// A non-null named type, e.g. `String!`
|
||||
NonNullNamed(String),
|
||||
NonNullNamed(&'a str),
|
||||
/// A non-null list type, e.g. `[String]!`.
|
||||
///
|
||||
/// The list itself is what's non-null, the containing type might be null.
|
||||
NonNullList(Box<Type>),
|
||||
NonNullList(Box<Type<'a>>),
|
||||
}
|
||||
|
||||
/// A JSON-like value that can be passed into the query execution, either
|
||||
|
@ -49,8 +49,8 @@ pub enum InputValue {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct VariableDefinition {
|
||||
pub var_type: Spanning<Type>,
|
||||
pub struct VariableDefinition<'a> {
|
||||
pub var_type: Spanning<Type<'a>>,
|
||||
pub default_value: Option<Spanning<InputValue>>,
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,8 @@ pub struct Arguments {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct VariableDefinitions {
|
||||
pub items: Vec<(Spanning<String>, VariableDefinition)>,
|
||||
pub struct VariableDefinitions<'a> {
|
||||
pub items: Vec<(Spanning<String>, VariableDefinition<'a>)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
|
@ -122,10 +122,10 @@ pub enum OperationType {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct Operation {
|
||||
pub struct Operation<'a> {
|
||||
pub operation_type: OperationType,
|
||||
pub name: Option<Spanning<String>>,
|
||||
pub variable_definitions: Option<Spanning<VariableDefinitions>>,
|
||||
pub variable_definitions: Option<Spanning<VariableDefinitions<'a>>>,
|
||||
pub directives: Option<Vec<Spanning<Directive>>>,
|
||||
pub selection_set: Vec<Selection>,
|
||||
}
|
||||
|
@ -139,12 +139,12 @@ pub struct Fragment {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum Definition {
|
||||
Operation(Spanning<Operation>),
|
||||
pub enum Definition<'a> {
|
||||
Operation(Spanning<Operation<'a>>),
|
||||
Fragment(Spanning<Fragment>),
|
||||
}
|
||||
|
||||
pub type Document = Vec<Definition>;
|
||||
pub type Document<'a> = Vec<Definition<'a>>;
|
||||
|
||||
/// Parse an unstructured input value into a Rust data type.
|
||||
///
|
||||
|
@ -163,7 +163,7 @@ pub trait ToInputValue: Sized {
|
|||
fn to(&self) -> InputValue;
|
||||
}
|
||||
|
||||
impl Type {
|
||||
impl<'a> Type<'a> {
|
||||
/// Get the name of a named type.
|
||||
///
|
||||
/// Only applies to named types; lists will return `None`.
|
||||
|
@ -193,7 +193,7 @@ impl Type {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Type {
|
||||
impl<'a> fmt::Display for Type<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Type::Named(ref n) => write!(f, "{}", n),
|
||||
|
@ -447,7 +447,7 @@ impl Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
impl VariableDefinitions {
|
||||
impl<'a> VariableDefinitions<'a> {
|
||||
pub fn iter(&self) -> slice::Iter<(Spanning<String>, VariableDefinition)> {
|
||||
self.items.iter()
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ use types::base::GraphQLType;
|
|||
/// The registry gathers metadata for all types in a schema. It provides
|
||||
/// convenience methods to convert types implementing the `GraphQLType` trait
|
||||
/// into `Type` instances and automatically registers them.
|
||||
pub struct Registry {
|
||||
pub struct Registry<'r> {
|
||||
/// Currently registered types
|
||||
pub types: HashMap<String, MetaType>,
|
||||
pub types: HashMap<String, MetaType<'r>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -38,7 +38,7 @@ pub struct Executor<'a, CtxT> where CtxT: 'a {
|
|||
fragments: &'a HashMap<&'a str, &'a Fragment>,
|
||||
variables: &'a HashMap<String, InputValue>,
|
||||
current_selection_set: Option<&'a [Selection]>,
|
||||
schema: &'a SchemaType,
|
||||
schema: &'a SchemaType<'a>,
|
||||
context: &'a CtxT,
|
||||
errors: &'a RwLock<Vec<ExecutionError>>,
|
||||
field_path: FieldPath<'a>,
|
||||
|
@ -353,9 +353,9 @@ pub fn execute_validated_query<'a, QueryT, MutationT, CtxT>(
|
|||
Ok((value, errors))
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
impl<'r> Registry<'r> {
|
||||
/// Construct a new registry
|
||||
pub fn new(types: HashMap<String, MetaType>) -> Registry {
|
||||
pub fn new(types: HashMap<String, MetaType<'r>>) -> Registry<'r> {
|
||||
Registry {
|
||||
types: types,
|
||||
}
|
||||
|
@ -365,10 +365,10 @@ impl Registry {
|
|||
///
|
||||
/// If the registry hasn't seen a type with this name before, it will
|
||||
/// construct its metadata and store it.
|
||||
pub fn get_type<T>(&mut self) -> Type where T: GraphQLType {
|
||||
pub fn get_type<T>(&mut self) -> Type<'r> where T: GraphQLType {
|
||||
if let Some(name) = T::name() {
|
||||
if !self.types.contains_key(name) {
|
||||
self.insert_placeholder(name, Type::NonNullNamed(name.to_owned()));
|
||||
self.insert_placeholder(name, Type::NonNullNamed(name));
|
||||
let meta = T::meta(self);
|
||||
self.types.insert(name.to_owned(), meta);
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ impl Registry {
|
|||
}
|
||||
|
||||
/// Create a field with the provided name
|
||||
pub fn field<T>(&mut self, name: &str) -> Field where T: GraphQLType {
|
||||
pub fn field<T>(&mut self, name: &str) -> Field<'r> where T: GraphQLType {
|
||||
Field {
|
||||
name: name.to_owned(),
|
||||
description: None,
|
||||
|
@ -391,7 +391,7 @@ impl Registry {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn field_convert<'a, T: IntoResolvable<'a, I, C>, I, C>(&mut self, name: &str) -> Field
|
||||
pub fn field_convert<'a, T: IntoResolvable<'a, I, C>, I, C>(&mut self, name: &str) -> Field<'r>
|
||||
where I: GraphQLType
|
||||
{
|
||||
Field {
|
||||
|
@ -404,7 +404,7 @@ impl Registry {
|
|||
}
|
||||
|
||||
/// Create an argument with the provided name
|
||||
pub fn arg<T>(&mut self, name: &str) -> Argument where T: GraphQLType + FromInputValue {
|
||||
pub fn arg<T>(&mut self, name: &str) -> Argument<'r> where T: GraphQLType + FromInputValue {
|
||||
Argument::new(name, self.get_type::<T>())
|
||||
}
|
||||
|
||||
|
@ -417,14 +417,14 @@ impl Registry {
|
|||
name: &str,
|
||||
value: &T,
|
||||
)
|
||||
-> Argument
|
||||
-> Argument<'r>
|
||||
where T: GraphQLType + ToInputValue + FromInputValue
|
||||
{
|
||||
Argument::new(name, self.get_type::<Option<T>>())
|
||||
.default_value(value.to())
|
||||
}
|
||||
|
||||
fn insert_placeholder(&mut self, name: &str, of_type: Type) {
|
||||
fn insert_placeholder(&mut self, name: &str, of_type: Type<'r>) {
|
||||
if !self.types.contains_key(name) {
|
||||
self.types.insert(
|
||||
name.to_owned(),
|
||||
|
@ -435,8 +435,7 @@ impl Registry {
|
|||
/// Create a scalar meta type
|
||||
///
|
||||
/// This expects the type to implement `FromInputValue`.
|
||||
pub fn build_scalar_type<T>(&mut self)
|
||||
-> ScalarMeta
|
||||
pub fn build_scalar_type<T>(&mut self) -> ScalarMeta<'r>
|
||||
where T: FromInputValue + GraphQLType
|
||||
{
|
||||
let name = T::name().expect("Scalar types must be named. Implement name()");
|
||||
|
@ -444,13 +443,13 @@ impl Registry {
|
|||
}
|
||||
|
||||
/// Create a list meta type
|
||||
pub fn build_list_type<T: GraphQLType>(&mut self) -> ListMeta {
|
||||
pub fn build_list_type<T: GraphQLType>(&mut self) -> ListMeta<'r> {
|
||||
let of_type = self.get_type::<T>();
|
||||
ListMeta::new(of_type)
|
||||
}
|
||||
|
||||
/// Create a nullable meta type
|
||||
pub fn build_nullable_type<T: GraphQLType>(&mut self) -> NullableMeta {
|
||||
pub fn build_nullable_type<T: GraphQLType>(&mut self) -> NullableMeta<'r> {
|
||||
let of_type = self.get_type::<T>();
|
||||
NullableMeta::new(of_type)
|
||||
}
|
||||
|
@ -459,62 +458,51 @@ impl Registry {
|
|||
///
|
||||
/// To prevent infinite recursion by enforcing ordering, this returns a
|
||||
/// function that needs to be called with the list of fields on the object.
|
||||
pub fn build_object_type<T>(&mut self)
|
||||
-> Box<Fn(&[Field]) -> ObjectMeta>
|
||||
pub fn build_object_type<T>(&mut self, fields: &[Field<'r>]) -> ObjectMeta<'r>
|
||||
where T: GraphQLType
|
||||
{
|
||||
let name = T::name().expect("Object types must be named. Implement name()");
|
||||
let typename_field = self.field::<String>("__typename");
|
||||
|
||||
Box::new(move |fs: &[Field]| {
|
||||
let mut v = fs.to_vec();
|
||||
v.push(typename_field.clone());
|
||||
ObjectMeta::new(name, &v)
|
||||
})
|
||||
let mut v = fields.to_vec();
|
||||
v.push(self.field::<String>("__typename"));
|
||||
ObjectMeta::new(name, &v)
|
||||
}
|
||||
|
||||
/// Create an enum meta type
|
||||
pub fn build_enum_type<T>(&mut self)
|
||||
-> Box<Fn(&[EnumValue]) -> EnumMeta>
|
||||
pub fn build_enum_type<T>(&mut self, values: &[EnumValue]) -> EnumMeta<'r>
|
||||
where T: FromInputValue + GraphQLType
|
||||
{
|
||||
let name = T::name().expect("Enum types must be named. Implement name()");
|
||||
|
||||
Box::new(move |values: &[EnumValue]| EnumMeta::new::<T>(name, values))
|
||||
EnumMeta::new::<T>(name, values)
|
||||
}
|
||||
|
||||
/// Create an interface meta type builder
|
||||
pub fn build_interface_type<T>(&mut self)
|
||||
-> Box<Fn(&[Field]) -> InterfaceMeta>
|
||||
pub fn build_interface_type<T>(&mut self, fields: &[Field<'r>]) -> InterfaceMeta<'r>
|
||||
where T: GraphQLType
|
||||
{
|
||||
let name = T::name().expect("Interface types must be named. Implement name()");
|
||||
let typename_field = self.field::<String>("__typename");
|
||||
|
||||
Box::new(move |fs: &[Field]| {
|
||||
let mut v = fs.to_vec();
|
||||
v.push(typename_field.clone());
|
||||
InterfaceMeta::new(name, &v)
|
||||
})
|
||||
let mut v = fields.to_vec();
|
||||
v.push(self.field::<String>("__typename"));
|
||||
InterfaceMeta::new(name, &v)
|
||||
}
|
||||
|
||||
/// Create a union meta type builder
|
||||
pub fn build_union_type<T>(&mut self)
|
||||
-> Box<Fn(&[Type]) -> UnionMeta>
|
||||
pub fn build_union_type<T>(&mut self, types: &[Type<'r>]) -> UnionMeta<'r>
|
||||
where T: GraphQLType
|
||||
{
|
||||
let name = T::name().expect("Union types must be named. Implement name()");
|
||||
|
||||
Box::new(move |ts: &[Type]| UnionMeta::new(name, ts))
|
||||
UnionMeta::new(name, types)
|
||||
}
|
||||
|
||||
/// Create an input object meta type builder
|
||||
pub fn build_input_object_type<T>(&mut self)
|
||||
-> Box<Fn(&[Argument]) -> InputObjectMeta>
|
||||
pub fn build_input_object_type<T>(&mut self, args: &[Argument<'r>]) -> InputObjectMeta<'r>
|
||||
where T: FromInputValue + GraphQLType
|
||||
{
|
||||
let name = T::name().expect("Input object types must be named. Implement name()");
|
||||
|
||||
Box::new(move |args: &[Argument]| InputObjectMeta::new::<T>(name, args))
|
||||
InputObjectMeta::new::<T>(name, args)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ use ::{InputValue, GraphQLType, RootNode, execute};
|
|||
/// this endpoint containing the field `"query"` and optionally `"variables"`.
|
||||
/// The variables should be a JSON object containing the variable to value
|
||||
/// mapping.
|
||||
pub struct GraphQLHandler<CtxFactory, Query, Mutation, CtxT>
|
||||
pub struct GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT>
|
||||
where CtxFactory: Fn(&mut Request) -> CtxT + Send + Sync + 'static,
|
||||
CtxT: 'static,
|
||||
Query: GraphQLType<Context=CtxT> + Send + Sync + 'static,
|
||||
Mutation: GraphQLType<Context=CtxT> + Send + Sync + 'static,
|
||||
{
|
||||
context_factory: CtxFactory,
|
||||
root_node: RootNode<Query, Mutation>,
|
||||
root_node: RootNode<'a, Query, Mutation>,
|
||||
}
|
||||
|
||||
/// Handler that renders GraphiQL - a graphical query editor interface
|
||||
|
@ -37,8 +37,8 @@ pub struct GraphiQLHandler {
|
|||
graphql_url: String,
|
||||
}
|
||||
|
||||
impl<CtxFactory, Query, Mutation, CtxT>
|
||||
GraphQLHandler<CtxFactory, Query, Mutation, CtxT>
|
||||
impl<'a, CtxFactory, Query, Mutation, CtxT>
|
||||
GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT>
|
||||
where CtxFactory: Fn(&mut Request) -> CtxT + Send + Sync + 'static,
|
||||
CtxT: 'static,
|
||||
Query: GraphQLType<Context=CtxT> + Send + Sync + 'static,
|
||||
|
@ -145,13 +145,13 @@ impl GraphiQLHandler {
|
|||
}
|
||||
}
|
||||
|
||||
impl<CtxFactory, Query, Mutation, CtxT>
|
||||
impl<'a, CtxFactory, Query, Mutation, CtxT>
|
||||
Handler
|
||||
for GraphQLHandler<CtxFactory, Query, Mutation, CtxT>
|
||||
for GraphQLHandler<'a, CtxFactory, Query, Mutation, CtxT>
|
||||
where CtxFactory: Fn(&mut Request) -> CtxT + Send + Sync + 'static,
|
||||
CtxT: 'static,
|
||||
Query: GraphQLType<Context=CtxT> + Send + Sync + 'static,
|
||||
Mutation: GraphQLType<Context=CtxT> + Send + Sync + 'static,
|
||||
Mutation: GraphQLType<Context=CtxT> + Send + Sync + 'static, 'a: 'static,
|
||||
{
|
||||
fn handle(&self, req: &mut Request) -> IronResult<Response> {
|
||||
match req.method {
|
||||
|
|
|
@ -66,10 +66,10 @@ macro_rules! graphql_enum {
|
|||
Some(graphql_enum!(@as_expr, $outname))
|
||||
}
|
||||
|
||||
fn meta(registry: &mut $crate::Registry) -> $crate::meta::MetaType {
|
||||
fn meta<'r>(registry: &mut $crate::Registry<'r>) -> $crate::meta::MetaType<'r> {
|
||||
graphql_enum!(
|
||||
@maybe_apply, $descr, description,
|
||||
registry.build_enum_type::<$name>()(&[
|
||||
registry.build_enum_type::<$name>(&[
|
||||
$(
|
||||
graphql_enum!(
|
||||
@maybe_apply,
|
||||
|
|
|
@ -155,12 +155,11 @@ macro_rules! graphql_input_object {
|
|||
Some($outname)
|
||||
}
|
||||
|
||||
fn meta(registry: &mut $crate::Registry) -> $crate::meta::MetaType {
|
||||
fn meta<'r>(registry: &mut $crate::Registry<'r>) -> $crate::meta::MetaType<'r> {
|
||||
let fields = graphql_input_object!(@generate_meta_fields, registry, $fields);
|
||||
graphql_input_object!(
|
||||
@maybe_apply, $descr, description,
|
||||
registry.build_input_object_type::<$name>()(
|
||||
graphql_input_object!(@generate_meta_fields, registry, $fields)
|
||||
)).into_meta()
|
||||
registry.build_input_object_type::<$name>(fields)).into_meta()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -236,11 +236,11 @@ macro_rules! graphql_interface {
|
|||
|
||||
#[allow(unused_assignments)]
|
||||
#[allow(unused_mut)]
|
||||
fn meta(registry: &mut $crate::Registry) -> $crate::meta::MetaType {
|
||||
fn meta<'r>(registry: &mut $crate::Registry<'r>) -> $crate::meta::MetaType<'r> {
|
||||
let mut fields = Vec::new();
|
||||
let mut description = None;
|
||||
graphql_interface!(@ gather_meta, (registry, fields, description), $($items)*);
|
||||
let mut mt = registry.build_interface_type::<$name>()(&fields);
|
||||
let mut mt = registry.build_interface_type::<$name>(&fields);
|
||||
|
||||
if let Some(description) = description {
|
||||
mt = mt.description(description);
|
||||
|
|
|
@ -357,7 +357,7 @@ macro_rules! graphql_object {
|
|||
|
||||
#[allow(unused_assignments)]
|
||||
#[allow(unused_mut)]
|
||||
fn meta(registry: &mut $crate::Registry) -> $crate::meta::MetaType {
|
||||
fn meta<'r>(registry: &mut $crate::Registry<'r>) -> $crate::meta::MetaType<'r> {
|
||||
let mut fields = Vec::new();
|
||||
let mut description = None;
|
||||
let mut interfaces: Option<Vec<$crate::Type>> = None;
|
||||
|
@ -365,7 +365,7 @@ macro_rules! graphql_object {
|
|||
@gather_object_meta,
|
||||
registry, fields, description, interfaces, $($items)*
|
||||
);
|
||||
let mut mt = registry.build_object_type::<$name>()(&fields);
|
||||
let mut mt = registry.build_object_type::<$name>(&fields);
|
||||
|
||||
if let Some(description) = description {
|
||||
mt = mt.description(description);
|
||||
|
|
|
@ -68,7 +68,7 @@ macro_rules! graphql_scalar {
|
|||
Some($outname)
|
||||
}
|
||||
|
||||
fn meta(registry: &mut $crate::Registry) -> $crate::meta::MetaType {
|
||||
fn meta<'r>(registry: &mut $crate::Registry<'r>) -> $crate::meta::MetaType<'r> {
|
||||
graphql_scalar!(
|
||||
@maybe_apply, $descr, description,
|
||||
registry.build_scalar_type::<Self>())
|
||||
|
|
|
@ -114,11 +114,11 @@ macro_rules! graphql_union {
|
|||
|
||||
#[allow(unused_assignments)]
|
||||
#[allow(unused_mut)]
|
||||
fn meta(registry: &mut $crate::Registry) -> $crate::meta::MetaType {
|
||||
fn meta<'r>(registry: &mut $crate::Registry<'r>) -> $crate::meta::MetaType<'r> {
|
||||
let mut types;
|
||||
let mut description = None;
|
||||
graphql_union!(@ gather_meta, (registry, types, description), $($items)*);
|
||||
let mut mt = registry.build_union_type::<$name>()(&types);
|
||||
let mut mt = registry.build_union_type::<$name>(&types);
|
||||
|
||||
if let Some(description) = description {
|
||||
mt = mt.description(description);
|
||||
|
|
|
@ -13,7 +13,7 @@ pub fn parse_document_source(s: &str) -> UnlocatedParseResult<Document> {
|
|||
parse_document(&mut parser)
|
||||
}
|
||||
|
||||
fn parse_document<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Document> {
|
||||
fn parse_document<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Document<'a>> {
|
||||
let mut defs = Vec::new();
|
||||
|
||||
loop {
|
||||
|
@ -25,7 +25,7 @@ fn parse_document<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Docum
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_definition<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Definition> {
|
||||
fn parse_definition<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Definition<'a>> {
|
||||
match parser.peek().item {
|
||||
Token::CurlyOpen | Token::Name("query") | Token::Name("mutation") =>
|
||||
Ok(Definition::Operation(try!(parse_operation_definition(parser)))),
|
||||
|
@ -35,7 +35,7 @@ fn parse_definition<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Def
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Operation> {
|
||||
fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Operation<'a>> {
|
||||
if parser.peek().item == Token::CurlyOpen {
|
||||
let selection_set = try!(parse_selection_set(parser));
|
||||
|
||||
|
@ -54,7 +54,7 @@ fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Op
|
|||
let start_pos = parser.peek().start.clone();
|
||||
let operation_type = try!(parse_operation_type(parser));
|
||||
let name = match parser.peek().item {
|
||||
Token::Name(_) => Some(try!(parser.expect_name())),
|
||||
Token::Name(_) => Some(try!(parser.expect_name()).map(|s| s.to_owned())),
|
||||
_ => None
|
||||
};
|
||||
let variable_definitions = try!(parse_variable_definitions(parser));
|
||||
|
@ -77,7 +77,7 @@ fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Op
|
|||
fn parse_fragment_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Fragment> {
|
||||
let Spanning { start: start_pos, .. } = try!(parser.expect(&Token::Name("fragment")));
|
||||
let name = match parser.expect_name() {
|
||||
Ok(n) => if &n.item == "on" {
|
||||
Ok(n) => if n.item == "on" {
|
||||
return Err(n.map(|_| ParseError::UnexpectedToken(Token::Name("on"))));
|
||||
}
|
||||
else {
|
||||
|
@ -95,8 +95,8 @@ fn parse_fragment_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Fra
|
|||
&start_pos,
|
||||
&selection_set.end,
|
||||
Fragment {
|
||||
name: name,
|
||||
type_condition: type_cond,
|
||||
name: name.map(|s| s.to_owned()),
|
||||
type_condition: type_cond.map(|s| s.to_owned()),
|
||||
directives: directives.map(|s| s.item),
|
||||
selection_set: selection_set.item,
|
||||
}))
|
||||
|
@ -140,7 +140,7 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
|||
&start_pos.clone(),
|
||||
&selection_set.end,
|
||||
InlineFragment {
|
||||
type_condition: Some(name),
|
||||
type_condition: Some(name.map(|s| s.to_owned())),
|
||||
directives: directives.map(|s| s.item),
|
||||
selection_set: selection_set.item,
|
||||
})))
|
||||
|
@ -167,7 +167,7 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
|||
&start_pos.clone(),
|
||||
&directives.as_ref().map_or(&frag_name.end, |s| &s.end).clone(),
|
||||
FragmentSpread {
|
||||
name: frag_name,
|
||||
name: frag_name.map(|s| s.to_owned()),
|
||||
directives: directives.map(|s| s.item),
|
||||
})))
|
||||
},
|
||||
|
@ -190,10 +190,10 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
|||
}
|
||||
|
||||
fn parse_field<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Field> {
|
||||
let mut alias = Some(try!(parser.expect_name()));
|
||||
let mut alias = Some(try!(parser.expect_name()).map(|s| s.to_owned()));
|
||||
|
||||
let name = if try!(parser.skip(&Token::Colon)).is_some() {
|
||||
try!(parser.expect_name())
|
||||
try!(parser.expect_name()).map(|s| s.to_owned())
|
||||
}
|
||||
else {
|
||||
alias.take().unwrap()
|
||||
|
@ -212,7 +212,7 @@ fn parse_field<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Field> {
|
|||
.clone(),
|
||||
Field {
|
||||
alias: alias,
|
||||
name: name,
|
||||
name: name.map(|s| s.to_owned()),
|
||||
arguments: arguments,
|
||||
directives: directives.map(|s| s.item),
|
||||
selection_set: selection_set.map(|s| s.item),
|
||||
|
@ -239,7 +239,7 @@ fn parse_argument<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, (Spanning<Stri
|
|||
Ok(Spanning::start_end(
|
||||
&name.start.clone(),
|
||||
&value.end.clone(),
|
||||
(name, value)))
|
||||
(name.map(|s| s.to_owned()), value)))
|
||||
}
|
||||
|
||||
fn parse_operation_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, OperationType> {
|
||||
|
@ -250,7 +250,7 @@ fn parse_operation_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Operatio
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_variable_definitions<'a>(parser: &mut Parser<'a>) -> OptionParseResult<'a, VariableDefinitions> {
|
||||
fn parse_variable_definitions<'a>(parser: &mut Parser<'a>) -> OptionParseResult<'a, VariableDefinitions<'a>> {
|
||||
if parser.peek().item != Token::ParenOpen {
|
||||
Ok(None)
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ fn parse_variable_definitions<'a>(parser: &mut Parser<'a>) -> OptionParseResult<
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_variable_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, (Spanning<String>, VariableDefinition)> {
|
||||
fn parse_variable_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, (Spanning<String>, VariableDefinition<'a>)> {
|
||||
let Spanning { start: start_pos, .. } = try!(parser.expect(&Token::Dollar));
|
||||
let var_name = try!(parser.expect_name());
|
||||
try!(parser.expect(&Token::Colon));
|
||||
|
@ -283,7 +283,7 @@ fn parse_variable_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, (Sp
|
|||
Spanning::start_end(
|
||||
&start_pos,
|
||||
&var_name.end,
|
||||
var_name.item
|
||||
var_name.item.to_owned(),
|
||||
),
|
||||
VariableDefinition {
|
||||
var_type: var_type,
|
||||
|
@ -315,23 +315,23 @@ fn parse_directive<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Directive> {
|
|||
&start_pos,
|
||||
&arguments.as_ref().map_or(&name.end, |s| &s.end).clone(),
|
||||
Directive {
|
||||
name: name,
|
||||
name: name.map(|s| s.to_owned()),
|
||||
arguments: arguments,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn parse_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Type> {
|
||||
pub fn parse_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Type<'a>> {
|
||||
let parsed_type = if let Some(Spanning { start: start_pos, ..}) = try!(parser.skip(&Token::BracketOpen)) {
|
||||
let inner_type = try!(parse_type(parser));
|
||||
let Spanning { end: end_pos, .. } = try!(parser.expect(&Token::BracketClose));
|
||||
Spanning::start_end(
|
||||
&start_pos,
|
||||
&end_pos,
|
||||
Type::List(Box::new(inner_type.item)))
|
||||
}
|
||||
else {
|
||||
try!(parser.expect_name()).map(Type::Named)
|
||||
};
|
||||
let inner_type = try!(parse_type(parser));
|
||||
let Spanning { end: end_pos, .. } = try!(parser.expect(&Token::BracketClose));
|
||||
Spanning::start_end(
|
||||
&start_pos,
|
||||
&end_pos,
|
||||
Type::List(Box::new(inner_type.item)))
|
||||
}
|
||||
else {
|
||||
try!(parser.expect_name()).map(Type::Named)
|
||||
};
|
||||
|
||||
Ok(match *parser.peek() {
|
||||
Spanning { item: Token::ExclamationMark, .. } =>
|
||||
|
@ -340,7 +340,7 @@ pub fn parse_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Type> {
|
|||
})
|
||||
}
|
||||
|
||||
fn wrap_non_null<'a>(parser: &mut Parser<'a>, inner: Spanning<Type>) -> ParseResult<'a, Type> {
|
||||
fn wrap_non_null<'a>(parser: &mut Parser<'a>, inner: Spanning<Type<'a>>) -> ParseResult<'a, Type<'a>> {
|
||||
let Spanning { end: end_pos, .. } = try!(parser.expect(&Token::ExclamationMark));
|
||||
|
||||
let wrapped = match inner.item {
|
||||
|
|
|
@ -148,12 +148,12 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn expect_name(&mut self) -> ParseResult<'a, String> {
|
||||
pub fn expect_name(&mut self) -> ParseResult<'a, &'a str> {
|
||||
match *self.peek() {
|
||||
Spanning { item: Token::Name(_), .. } =>
|
||||
Ok(self.next().map(|token|
|
||||
if let Token::Name(name) = token {
|
||||
name.to_owned()
|
||||
name
|
||||
}
|
||||
else {
|
||||
panic!("Internal parse error in `expect_name`");
|
||||
|
|
|
@ -57,7 +57,7 @@ fn parse_object_field<'a>(parser: &mut Parser<'a>, is_const: bool) -> ParseResul
|
|||
Ok(Spanning::start_end(
|
||||
&key.start.clone(),
|
||||
&value.end.clone(),
|
||||
(key, value)))
|
||||
(key.map(|s| s.to_owned()), value)))
|
||||
}
|
||||
|
||||
fn parse_variable_literal<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, InputValue> {
|
||||
|
|
|
@ -7,9 +7,9 @@ use ast::{InputValue, FromInputValue, Type};
|
|||
use types::base::TypeKind;
|
||||
|
||||
/// Scalar type metadata
|
||||
pub struct ScalarMeta {
|
||||
pub struct ScalarMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
pub name: &'a str,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
|
@ -18,35 +18,35 @@ pub struct ScalarMeta {
|
|||
|
||||
/// List type metadata
|
||||
#[derive(Debug)]
|
||||
pub struct ListMeta {
|
||||
pub struct ListMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub of_type: Type,
|
||||
pub of_type: Type<'a>,
|
||||
}
|
||||
|
||||
/// Nullable type metadata
|
||||
#[derive(Debug)]
|
||||
pub struct NullableMeta {
|
||||
pub struct NullableMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub of_type: Type,
|
||||
pub of_type: Type<'a>,
|
||||
}
|
||||
|
||||
/// Object type metadata
|
||||
#[derive(Debug)]
|
||||
pub struct ObjectMeta {
|
||||
pub struct ObjectMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
pub name: &'a str,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
pub fields: Vec<Field>,
|
||||
pub fields: Vec<Field<'a>>,
|
||||
#[doc(hidden)]
|
||||
pub interface_names: Vec<String>,
|
||||
}
|
||||
|
||||
/// Enum type metadata
|
||||
pub struct EnumMeta {
|
||||
pub struct EnumMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
pub name: &'a str,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
|
@ -57,20 +57,20 @@ pub struct EnumMeta {
|
|||
|
||||
/// Interface type metadata
|
||||
#[derive(Debug)]
|
||||
pub struct InterfaceMeta {
|
||||
pub struct InterfaceMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
pub name: &'a str,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
pub fields: Vec<Field>,
|
||||
pub fields: Vec<Field<'a>>,
|
||||
}
|
||||
|
||||
/// Union type metadata
|
||||
#[derive(Debug)]
|
||||
pub struct UnionMeta {
|
||||
pub struct UnionMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
pub name: &'a str,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
|
@ -78,13 +78,13 @@ pub struct UnionMeta {
|
|||
}
|
||||
|
||||
/// Input object metadata
|
||||
pub struct InputObjectMeta {
|
||||
pub struct InputObjectMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
pub name: &'a str,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
pub input_fields: Vec<Argument>,
|
||||
pub input_fields: Vec<Argument<'a>>,
|
||||
#[doc(hidden)]
|
||||
pub try_parse_fn: Box<Fn(&InputValue) -> bool + Send + Sync>,
|
||||
}
|
||||
|
@ -94,58 +94,58 @@ pub struct InputObjectMeta {
|
|||
/// After a type's `meta` method has been called but before it has returned, a placeholder type
|
||||
/// is inserted into a registry to indicate existence.
|
||||
#[derive(Debug)]
|
||||
pub struct PlaceholderMeta {
|
||||
pub struct PlaceholderMeta<'a> {
|
||||
#[doc(hidden)]
|
||||
pub of_type: Type,
|
||||
pub of_type: Type<'a>,
|
||||
}
|
||||
|
||||
/// Generic type metadata
|
||||
#[derive(Debug)]
|
||||
pub enum MetaType {
|
||||
pub enum MetaType<'a> {
|
||||
#[doc(hidden)]
|
||||
Scalar(ScalarMeta),
|
||||
Scalar(ScalarMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
List(ListMeta),
|
||||
List(ListMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
Nullable(NullableMeta),
|
||||
Nullable(NullableMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
Object(ObjectMeta),
|
||||
Object(ObjectMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
Enum(EnumMeta),
|
||||
Enum(EnumMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
Interface(InterfaceMeta),
|
||||
Interface(InterfaceMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
Union(UnionMeta),
|
||||
Union(UnionMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
InputObject(InputObjectMeta),
|
||||
InputObject(InputObjectMeta<'a>),
|
||||
#[doc(hidden)]
|
||||
Placeholder(PlaceholderMeta),
|
||||
Placeholder(PlaceholderMeta<'a>),
|
||||
}
|
||||
|
||||
/// Metadata for a field
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Field {
|
||||
pub struct Field<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
pub arguments: Option<Vec<Argument>>,
|
||||
pub arguments: Option<Vec<Argument<'a>>>,
|
||||
#[doc(hidden)]
|
||||
pub field_type: Type,
|
||||
pub field_type: Type<'a>,
|
||||
#[doc(hidden)]
|
||||
pub deprecation_reason: Option<String>,
|
||||
}
|
||||
|
||||
/// Metadata for an argument to a field
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Argument {
|
||||
pub struct Argument<'a> {
|
||||
#[doc(hidden)]
|
||||
pub name: String,
|
||||
#[doc(hidden)]
|
||||
pub description: Option<String>,
|
||||
#[doc(hidden)]
|
||||
pub arg_type: Type,
|
||||
pub arg_type: Type<'a>,
|
||||
#[doc(hidden)]
|
||||
pub default_value: Option<InputValue>,
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ pub struct EnumValue {
|
|||
pub deprecation_reason: Option<String>,
|
||||
}
|
||||
|
||||
impl MetaType {
|
||||
impl<'a> MetaType<'a> {
|
||||
/// Access the name of the type, if applicable
|
||||
///
|
||||
/// Lists, non-null wrappers, and placeholders don't have names.
|
||||
|
@ -243,7 +243,7 @@ impl MetaType {
|
|||
}
|
||||
|
||||
/// Construct a `Type` literal instance based on the metadata
|
||||
pub fn as_type(&self) -> Type {
|
||||
pub fn as_type(&self) -> Type<'a> {
|
||||
match *self {
|
||||
MetaType::Scalar(ScalarMeta { ref name, .. }) |
|
||||
MetaType::Object(ObjectMeta { ref name, .. }) |
|
||||
|
@ -251,7 +251,7 @@ impl MetaType {
|
|||
MetaType::Interface(InterfaceMeta { ref name, .. }) |
|
||||
MetaType::Union(UnionMeta { ref name, .. }) |
|
||||
MetaType::InputObject(InputObjectMeta { ref name, .. }) =>
|
||||
Type::NonNullNamed(name.to_owned()),
|
||||
Type::NonNullNamed(name),
|
||||
MetaType::List(ListMeta { ref of_type }) =>
|
||||
Type::NonNullList(Box::new(of_type.clone())),
|
||||
MetaType::Nullable(NullableMeta { ref of_type }) =>
|
||||
|
@ -327,11 +327,11 @@ impl MetaType {
|
|||
}
|
||||
}
|
||||
|
||||
impl ScalarMeta {
|
||||
impl<'a> ScalarMeta<'a> {
|
||||
/// Build a new scalar type metadata with the specified name
|
||||
pub fn new<T: FromInputValue>(name: &str) -> ScalarMeta {
|
||||
pub fn new<T: FromInputValue>(name: &'a str) -> ScalarMeta<'a> {
|
||||
ScalarMeta {
|
||||
name: name.to_owned(),
|
||||
name: name,
|
||||
description: None,
|
||||
try_parse_fn: Box::new(
|
||||
|v: &InputValue| <T as FromInputValue>::from(v).is_some()),
|
||||
|
@ -341,50 +341,50 @@ impl ScalarMeta {
|
|||
/// Set the description for the given scalar type
|
||||
///
|
||||
/// If a description already was set prior to calling this method, it will be overwritten.
|
||||
pub fn description(mut self, description: &str) -> ScalarMeta {
|
||||
pub fn description(mut self, description: &str) -> ScalarMeta<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Wrap the scalar in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::Scalar(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ListMeta {
|
||||
impl<'a> ListMeta<'a> {
|
||||
/// Build a new list type by wrapping the specified type
|
||||
pub fn new(of_type: Type) -> ListMeta {
|
||||
pub fn new(of_type: Type<'a>) -> ListMeta<'a> {
|
||||
ListMeta {
|
||||
of_type: of_type,
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrap the list in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::List(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl NullableMeta {
|
||||
impl<'a> NullableMeta<'a> {
|
||||
/// Build a new nullable type by wrapping the specified type
|
||||
pub fn new(of_type: Type) -> NullableMeta {
|
||||
pub fn new(of_type: Type<'a>) -> NullableMeta<'a> {
|
||||
NullableMeta {
|
||||
of_type: of_type,
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrap the nullable type in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::Nullable(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectMeta {
|
||||
impl<'a> ObjectMeta<'a> {
|
||||
/// Build a new object type with the specified name and fields
|
||||
pub fn new(name: &str, fields: &[Field]) -> ObjectMeta {
|
||||
pub fn new(name: &'a str, fields: &[Field<'a>]) -> ObjectMeta<'a> {
|
||||
ObjectMeta {
|
||||
name: name.to_owned(),
|
||||
name: name,
|
||||
description: None,
|
||||
fields: fields.to_vec(),
|
||||
interface_names: vec![],
|
||||
|
@ -394,32 +394,32 @@ impl ObjectMeta {
|
|||
/// Set the description for the object
|
||||
///
|
||||
/// If a description was provided prior to calling this method, it will be overwritten.
|
||||
pub fn description(mut self, description: &str) -> ObjectMeta {
|
||||
pub fn description(mut self, description: &str) -> ObjectMeta<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the interfaces this type implements
|
||||
///
|
||||
/// If a list of interfaces already was provided prior to calling this method, they will be
|
||||
/// If a list of interfaces already was provided prior to calling this method, they will be
|
||||
/// overwritten.
|
||||
pub fn interfaces(mut self, interfaces: &[Type]) -> ObjectMeta {
|
||||
pub fn interfaces(mut self, interfaces: &[Type<'a>]) -> ObjectMeta<'a> {
|
||||
self.interface_names = interfaces.iter()
|
||||
.map(|t| t.innermost_name().to_owned()).collect();
|
||||
self
|
||||
}
|
||||
|
||||
/// Wrap this object type in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::Object(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl EnumMeta {
|
||||
impl<'a> EnumMeta<'a> {
|
||||
/// Build a new enum type with the specified name and possible values
|
||||
pub fn new<T: FromInputValue>(name: &str, values: &[EnumValue]) -> EnumMeta {
|
||||
pub fn new<T: FromInputValue>(name: &'a str, values: &[EnumValue]) -> EnumMeta<'a> {
|
||||
EnumMeta {
|
||||
name: name.to_owned(),
|
||||
name: name,
|
||||
description: None,
|
||||
values: values.to_vec(),
|
||||
try_parse_fn: Box::new(
|
||||
|
@ -430,22 +430,22 @@ impl EnumMeta {
|
|||
/// Set the description of the type
|
||||
///
|
||||
/// If a description was provided prior to calling this method, it will be overwritten
|
||||
pub fn description(mut self, description: &str) -> EnumMeta {
|
||||
pub fn description(mut self, description: &str) -> EnumMeta<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Wrap this enum type in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::Enum(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl InterfaceMeta {
|
||||
impl<'a> InterfaceMeta<'a> {
|
||||
/// Build a new interface type with the specified name and fields
|
||||
pub fn new(name: &str, fields: &[Field]) -> InterfaceMeta {
|
||||
pub fn new(name: &'a str, fields: &[Field<'a>]) -> InterfaceMeta<'a> {
|
||||
InterfaceMeta {
|
||||
name: name.to_owned(),
|
||||
name: name,
|
||||
description: None,
|
||||
fields: fields.to_vec(),
|
||||
}
|
||||
|
@ -454,22 +454,22 @@ impl InterfaceMeta {
|
|||
/// Set the description of the type
|
||||
///
|
||||
/// If a description was provided prior to calling this method, it will be overwritten.
|
||||
pub fn description(mut self, description: &str) -> InterfaceMeta {
|
||||
pub fn description(mut self, description: &str) -> InterfaceMeta<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Wrap this interface type in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::Interface(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl UnionMeta {
|
||||
impl<'a> UnionMeta<'a> {
|
||||
/// Build a new union type with the specified name and possible types
|
||||
pub fn new(name: &str, of_types: &[Type]) -> UnionMeta {
|
||||
pub fn new(name: &'a str, of_types: &[Type]) -> UnionMeta<'a> {
|
||||
UnionMeta {
|
||||
name: name.to_owned(),
|
||||
name: name,
|
||||
description: None,
|
||||
of_type_names: of_types.iter()
|
||||
.map(|t| t.innermost_name().to_owned()).collect(),
|
||||
|
@ -479,22 +479,22 @@ impl UnionMeta {
|
|||
/// Set the description of the type
|
||||
///
|
||||
/// If a description was provided prior to calling this method, it will be overwritten.
|
||||
pub fn description(mut self, description: &str) -> UnionMeta {
|
||||
pub fn description(mut self, description: &str) -> UnionMeta<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Wrap this union type in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::Union(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl InputObjectMeta {
|
||||
impl<'a> InputObjectMeta<'a> {
|
||||
/// Build a new input type with the specified name and input fields
|
||||
pub fn new<T: FromInputValue>(name: &str, input_fields: &[Argument]) -> InputObjectMeta {
|
||||
pub fn new<T: FromInputValue>(name: &'a str, input_fields: &[Argument<'a>]) -> InputObjectMeta<'a> {
|
||||
InputObjectMeta {
|
||||
name: name.to_owned(),
|
||||
name: name,
|
||||
description: None,
|
||||
input_fields: input_fields.to_vec(),
|
||||
try_parse_fn: Box::new(
|
||||
|
@ -505,22 +505,22 @@ impl InputObjectMeta {
|
|||
/// Set the description of the type
|
||||
///
|
||||
/// If a description was provided prior to calling this method, it will be overwritten.
|
||||
pub fn description(mut self, description: &str) -> InputObjectMeta {
|
||||
pub fn description(mut self, description: &str) -> InputObjectMeta<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Wrap this union type in a generic meta type
|
||||
pub fn into_meta(self) -> MetaType {
|
||||
pub fn into_meta(self) -> MetaType<'a> {
|
||||
MetaType::InputObject(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Field {
|
||||
impl<'a> Field<'a> {
|
||||
/// Set the description of the field
|
||||
///
|
||||
/// This overwrites the description if any was previously set.
|
||||
pub fn description(mut self, description: &str) -> Field {
|
||||
pub fn description(mut self, description: &str) -> Field<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ impl Field {
|
|||
/// Add an argument to the field
|
||||
///
|
||||
/// Arguments are unordered and can't contain duplicates by name.
|
||||
pub fn argument(mut self, argument: Argument) -> Field {
|
||||
pub fn argument(mut self, argument: Argument<'a>) -> Field<'a> {
|
||||
match self.arguments {
|
||||
None => { self.arguments = Some(vec![argument]); }
|
||||
Some(ref mut args) => { args.push(argument); }
|
||||
|
@ -540,15 +540,15 @@ impl Field {
|
|||
/// Set the deprecation reason
|
||||
///
|
||||
/// This overwrites the deprecation reason if any was previously set.
|
||||
pub fn deprecated(mut self, reason: &str) -> Field {
|
||||
pub fn deprecated(mut self, reason: &str) -> Field<'a> {
|
||||
self.deprecation_reason = Some(reason.to_owned());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Argument {
|
||||
impl<'a> Argument<'a> {
|
||||
#[doc(hidden)]
|
||||
pub fn new(name: &str, arg_type: Type) -> Argument {
|
||||
pub fn new(name: &str, arg_type: Type<'a>) -> Argument<'a> {
|
||||
Argument {
|
||||
name: name.to_owned(),
|
||||
description: None,
|
||||
|
@ -560,7 +560,7 @@ impl Argument {
|
|||
/// Set the description of the argument
|
||||
///
|
||||
/// This overwrites the description if any was previously set.
|
||||
pub fn description(mut self, description: &str) -> Argument {
|
||||
pub fn description(mut self, description: &str) -> Argument<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ impl Argument {
|
|||
/// Set the default value of the argument
|
||||
///
|
||||
/// This overwrites the description if any was previously set.
|
||||
pub fn default_value(mut self, default_value: InputValue) -> Argument {
|
||||
pub fn default_value(mut self, default_value: InputValue) -> Argument<'a> {
|
||||
self.default_value = Some(default_value);
|
||||
self
|
||||
}
|
||||
|
@ -601,7 +601,7 @@ impl EnumValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ScalarMeta {
|
||||
impl<'a> fmt::Debug for ScalarMeta<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("ScalarMeta")
|
||||
.field("name", &self.name)
|
||||
|
@ -610,7 +610,7 @@ impl fmt::Debug for ScalarMeta {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for EnumMeta {
|
||||
impl<'a> fmt::Debug for EnumMeta<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("EnumMeta")
|
||||
.field("name", &self.name)
|
||||
|
@ -620,7 +620,7 @@ impl fmt::Debug for EnumMeta {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for InputObjectMeta {
|
||||
impl<'a> fmt::Debug for InputObjectMeta<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("InputObjectMeta")
|
||||
.field("name", &self.name)
|
||||
|
|
|
@ -10,36 +10,36 @@ use schema::meta::{MetaType, ObjectMeta, PlaceholderMeta, UnionMeta, InterfaceMe
|
|||
///
|
||||
/// This brings the mutation and query types together, and provides the
|
||||
/// predefined metadata fields.
|
||||
pub struct RootNode<QueryT, MutationT> {
|
||||
pub struct RootNode<'a, QueryT, MutationT> {
|
||||
#[doc(hidden)]
|
||||
pub query_type: QueryT,
|
||||
#[doc(hidden)]
|
||||
pub mutation_type: MutationT,
|
||||
#[doc(hidden)]
|
||||
pub schema: SchemaType,
|
||||
pub schema: SchemaType<'a>,
|
||||
}
|
||||
|
||||
/// Metadata for a schema
|
||||
pub struct SchemaType {
|
||||
types: HashMap<String, MetaType>,
|
||||
pub struct SchemaType<'a> {
|
||||
types: HashMap<String, MetaType<'a>>,
|
||||
query_type_name: String,
|
||||
mutation_type_name: Option<String>,
|
||||
directives: HashMap<String, DirectiveType>,
|
||||
directives: HashMap<String, DirectiveType<'a>>,
|
||||
}
|
||||
|
||||
impl Context for SchemaType {}
|
||||
impl<'a> Context for SchemaType<'a> {}
|
||||
|
||||
pub enum TypeType<'a> {
|
||||
Concrete(&'a MetaType),
|
||||
Concrete(&'a MetaType<'a>),
|
||||
NonNull(Box<TypeType<'a>>),
|
||||
List(Box<TypeType<'a>>),
|
||||
}
|
||||
|
||||
pub struct DirectiveType {
|
||||
pub struct DirectiveType<'a> {
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub locations: Vec<DirectiveLocation>,
|
||||
pub arguments: Vec<Argument>,
|
||||
pub arguments: Vec<Argument<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
|
@ -52,7 +52,7 @@ pub enum DirectiveLocation {
|
|||
InlineFragment,
|
||||
}
|
||||
|
||||
impl<QueryT, MutationT> RootNode<QueryT, MutationT>
|
||||
impl<'a, QueryT, MutationT> RootNode<'a, QueryT, MutationT>
|
||||
where QueryT: GraphQLType,
|
||||
MutationT: GraphQLType,
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ impl<QueryT, MutationT> RootNode<QueryT, MutationT>
|
|||
///
|
||||
/// If the schema should not support mutations, use the
|
||||
/// `new` constructor instead.
|
||||
pub fn new(query_obj: QueryT, mutation_obj: MutationT) -> RootNode<QueryT, MutationT> {
|
||||
pub fn new(query_obj: QueryT, mutation_obj: MutationT) -> RootNode<'a, QueryT, MutationT> {
|
||||
RootNode {
|
||||
query_type: query_obj,
|
||||
mutation_type: mutation_obj,
|
||||
|
@ -69,8 +69,8 @@ impl<QueryT, MutationT> RootNode<QueryT, MutationT>
|
|||
}
|
||||
}
|
||||
|
||||
impl SchemaType {
|
||||
pub fn new<QueryT, MutationT>() -> SchemaType
|
||||
impl<'a> SchemaType<'a> {
|
||||
pub fn new<QueryT, MutationT>() -> SchemaType<'a>
|
||||
where QueryT: GraphQLType,
|
||||
MutationT: GraphQLType,
|
||||
{
|
||||
|
@ -122,7 +122,7 @@ impl SchemaType {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_directive(&mut self, directive: DirectiveType) {
|
||||
pub fn add_directive(&mut self, directive: DirectiveType<'a>) {
|
||||
self.directives.insert(directive.name.clone(), directive);
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ impl SchemaType {
|
|||
.any(|t| (t as *const MetaType) == (possible_type as *const MetaType))
|
||||
}
|
||||
|
||||
pub fn is_subtype(&self, sub_type: &Type, super_type: &Type) -> bool {
|
||||
pub fn is_subtype<'b>(&self, sub_type: &Type<'b>, super_type: &Type<'b>) -> bool {
|
||||
use ast::Type::*;
|
||||
|
||||
if super_type == sub_type {
|
||||
|
@ -274,8 +274,8 @@ impl<'a> TypeType<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl DirectiveType {
|
||||
pub fn new(name: &str, locations: &[DirectiveLocation], arguments: &[Argument]) -> DirectiveType {
|
||||
impl<'a> DirectiveType<'a> {
|
||||
pub fn new(name: &str, locations: &[DirectiveLocation], arguments: &[Argument<'a>]) -> DirectiveType<'a> {
|
||||
DirectiveType {
|
||||
name: name.to_owned(),
|
||||
description: None,
|
||||
|
@ -284,7 +284,7 @@ impl DirectiveType {
|
|||
}
|
||||
}
|
||||
|
||||
fn new_skip(registry: &mut Registry) -> DirectiveType {
|
||||
fn new_skip(registry: &mut Registry<'a>) -> DirectiveType<'a> {
|
||||
Self::new(
|
||||
"skip",
|
||||
&[
|
||||
|
@ -297,7 +297,7 @@ impl DirectiveType {
|
|||
])
|
||||
}
|
||||
|
||||
fn new_include(registry: &mut Registry) -> DirectiveType {
|
||||
fn new_include(registry: &mut Registry<'a>) -> DirectiveType<'a> {
|
||||
Self::new(
|
||||
"include",
|
||||
&[
|
||||
|
@ -310,7 +310,7 @@ impl DirectiveType {
|
|||
])
|
||||
}
|
||||
|
||||
pub fn description(mut self, description: &str) -> DirectiveType {
|
||||
pub fn description(mut self, description: &str) -> DirectiveType<'a> {
|
||||
self.description = Some(description.to_owned());
|
||||
self
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use schema::meta::{MetaType, ObjectMeta, EnumMeta, InputObjectMeta, UnionMeta, I
|
|||
Field, Argument, EnumValue};
|
||||
use schema::model::{RootNode, SchemaType, TypeType, DirectiveType, DirectiveLocation};
|
||||
|
||||
impl<CtxT, QueryT, MutationT> GraphQLType for RootNode<QueryT, MutationT>
|
||||
impl<'a, CtxT, QueryT, MutationT> GraphQLType for RootNode<'a, QueryT, MutationT>
|
||||
where QueryT: GraphQLType<Context=CtxT>,
|
||||
MutationT: GraphQLType<Context=CtxT>
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ impl<CtxT, QueryT, MutationT> GraphQLType for RootNode<QueryT, MutationT>
|
|||
QueryT::name()
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
QueryT::meta(registry)
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ impl<CtxT, QueryT, MutationT> GraphQLType for RootNode<QueryT, MutationT>
|
|||
}
|
||||
}
|
||||
|
||||
graphql_object!(SchemaType: SchemaType as "__Schema" |&self| {
|
||||
graphql_object!(<'a> SchemaType<'a>: SchemaType<'a> as "__Schema" |&self| {
|
||||
field types() -> Vec<TypeType> {
|
||||
self.type_list()
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ graphql_object!(SchemaType: SchemaType as "__Schema" |&self| {
|
|||
}
|
||||
});
|
||||
|
||||
graphql_object!(<'a> TypeType<'a>: SchemaType as "__Type" |&self| {
|
||||
graphql_object!(<'a> TypeType<'a>: SchemaType<'a> as "__Type" |&self| {
|
||||
field name() -> Option<&str> {
|
||||
match *self {
|
||||
TypeType::Concrete(t) => t.name(),
|
||||
|
@ -123,12 +123,12 @@ graphql_object!(<'a> TypeType<'a>: SchemaType as "__Type" |&self| {
|
|||
.filter_map(|tn| schema.type_by_name(tn))
|
||||
.collect())
|
||||
}
|
||||
TypeType::Concrete(&MetaType::Interface(InterfaceMeta { name: ref iface_name, .. })) => {
|
||||
TypeType::Concrete(&MetaType::Interface(InterfaceMeta { name: iface_name, .. })) => {
|
||||
Some(schema.concrete_type_list()
|
||||
.iter()
|
||||
.filter_map(|&ct|
|
||||
if let &MetaType::Object(ObjectMeta { ref name, ref interface_names, .. }) = ct {
|
||||
if interface_names.contains(iface_name) {
|
||||
if interface_names.contains(&iface_name.to_owned()) {
|
||||
schema.type_by_name(name)
|
||||
} else { None }
|
||||
} else { None }
|
||||
|
@ -151,7 +151,7 @@ graphql_object!(<'a> TypeType<'a>: SchemaType as "__Type" |&self| {
|
|||
}
|
||||
});
|
||||
|
||||
graphql_object!(Field: SchemaType as "__Field" |&self| {
|
||||
graphql_object!(<'a> Field<'a>: SchemaType<'a> as "__Field" |&self| {
|
||||
field name() -> &String {
|
||||
&self.name
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ graphql_object!(Field: SchemaType as "__Field" |&self| {
|
|||
}
|
||||
});
|
||||
|
||||
graphql_object!(Argument: SchemaType as "__InputValue" |&self| {
|
||||
graphql_object!(<'a> Argument<'a>: SchemaType<'a> as "__InputValue" |&self| {
|
||||
field name() -> &String {
|
||||
&self.name
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ graphql_object!(Argument: SchemaType as "__InputValue" |&self| {
|
|||
}
|
||||
});
|
||||
|
||||
graphql_object!(EnumValue: SchemaType as "__EnumValue" |&self| {
|
||||
graphql_object!(EnumValue: () as "__EnumValue" |&self| {
|
||||
field name() -> &String {
|
||||
&self.name
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ graphql_enum!(TypeKind as "__TypeKind" {
|
|||
});
|
||||
|
||||
|
||||
graphql_object!(DirectiveType: SchemaType as "__Directive" |&self| {
|
||||
graphql_object!(<'a> DirectiveType<'a>: SchemaType<'a> as "__Directive" |&self| {
|
||||
field name() -> &String {
|
||||
&self.name
|
||||
}
|
||||
|
|
|
@ -152,17 +152,18 @@ impl GraphQLType for User {
|
|||
Some("User")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
// First, we need to define all fields and their types on this type.
|
||||
//
|
||||
// If we need arguments, want to implement interfaces, or want to add
|
||||
// documentation strings, we can do it here.
|
||||
registry.build_object_type::<User>()(&[
|
||||
registry.field::<&String>("id"),
|
||||
registry.field::<&String>("name"),
|
||||
registry.field::<Vec<&User>>("friends"),
|
||||
])
|
||||
.into_meta()
|
||||
let fields = &[
|
||||
registry.field::<&String>("id"),
|
||||
registry.field::<&String>("name"),
|
||||
registry.field::<Vec<&User>>("friends"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<User>(fields).into_meta()
|
||||
}
|
||||
|
||||
fn resolve_field(
|
||||
|
@ -224,7 +225,7 @@ pub trait GraphQLType: Sized {
|
|||
fn name() -> Option<&'static str>;
|
||||
|
||||
/// The meta type representing this GraphQL type.
|
||||
fn meta(registry: &mut Registry) -> MetaType;
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r>;
|
||||
|
||||
/// Resolve the value of a single field on this type.
|
||||
///
|
||||
|
|
|
@ -12,7 +12,7 @@ impl<T, CtxT> GraphQLType for Option<T> where T: GraphQLType<Context=CtxT> {
|
|||
None
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_nullable_type::<T>().into_meta()
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ impl<T, CtxT> GraphQLType for Vec<T> where T: GraphQLType<Context=CtxT> {
|
|||
None
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_list_type::<T>().into_meta()
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ impl<'a, T, CtxT> GraphQLType for &'a [T] where T: GraphQLType<Context=CtxT> {
|
|||
None
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_list_type::<T>().into_meta()
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ impl<T, CtxT> GraphQLType for Box<T> where T: GraphQLType<Context=CtxT> {
|
|||
T::name()
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
T::meta(registry)
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ impl<'a, T, CtxT> GraphQLType for &'a T where T: GraphQLType<Context=CtxT> {
|
|||
T::name()
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
T::meta(registry)
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<'a> GraphQLType for &'a str {
|
|||
Some("String")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_scalar_type::<String>().into_meta()
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ impl GraphQLType for () {
|
|||
Some("__Unit")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_scalar_type::<Self>().into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ impl<T> GraphQLType for EmptyMutation<T> {
|
|||
Some("__EmptyMutation")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[]).into_meta()
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_object_type::<Self>(&[]).into_meta()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ pub struct RuleError {
|
|||
|
||||
#[doc(hidden)]
|
||||
pub struct ValidatorContext<'a> {
|
||||
pub schema: &'a SchemaType,
|
||||
pub schema: &'a SchemaType<'a>,
|
||||
errors: Vec<RuleError>,
|
||||
type_stack: Vec<Option<&'a MetaType>>,
|
||||
type_literal_stack: Vec<Option<Type>>,
|
||||
input_type_stack: Vec<Option<&'a MetaType>>,
|
||||
input_type_literal_stack: Vec<Option<Type>>,
|
||||
parent_type_stack: Vec<Option<&'a MetaType>>,
|
||||
type_stack: Vec<Option<&'a MetaType<'a>>>,
|
||||
type_literal_stack: Vec<Option<Type<'a>>>,
|
||||
input_type_stack: Vec<Option<&'a MetaType<'a>>>,
|
||||
input_type_literal_stack: Vec<Option<Type<'a>>>,
|
||||
parent_type_stack: Vec<Option<&'a MetaType<'a>>>,
|
||||
fragment_names: HashSet<String>,
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ impl<'a> ValidatorContext<'a> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn with_pushed_type<F, R>(&mut self, t: Option<&Type>, f: F)
|
||||
pub fn with_pushed_type<F, R>(&mut self, t: Option<&Type<'a>>, f: F)
|
||||
-> R
|
||||
where F: FnOnce(&mut ValidatorContext<'a>) -> R
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ impl<'a> ValidatorContext<'a> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn with_pushed_input_type<F, R>(&mut self, t: Option<&Type>, f: F)
|
||||
pub fn with_pushed_input_type<F, R>(&mut self, t: Option<&Type<'a>>, f: F)
|
||||
-> R
|
||||
where F: FnOnce(&mut ValidatorContext<'a>) -> R
|
||||
{
|
||||
|
@ -142,12 +142,12 @@ impl<'a> ValidatorContext<'a> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn current_type(&self) -> Option<&'a MetaType> {
|
||||
pub fn current_type(&self) -> Option<&'a MetaType<'a>> {
|
||||
*self.type_stack.last().unwrap_or(&None)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn current_type_literal(&self) -> Option<&Type> {
|
||||
pub fn current_type_literal(&self) -> Option<&Type<'a>> {
|
||||
match self.type_literal_stack.last() {
|
||||
Some(&Some(ref t)) => Some(t),
|
||||
_ => None
|
||||
|
@ -155,12 +155,12 @@ impl<'a> ValidatorContext<'a> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn parent_type(&self) -> Option<&'a MetaType> {
|
||||
pub fn parent_type(&self) -> Option<&'a MetaType<'a>> {
|
||||
*self.parent_type_stack.last().unwrap_or(&None)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn current_input_type_literal(&self) -> Option<&Type> {
|
||||
pub fn current_input_type_literal(&self) -> Option<&Type<'a>> {
|
||||
match self.input_type_literal_stack.last() {
|
||||
Some(&Some(ref t)) => Some(t),
|
||||
_ => None,
|
||||
|
|
|
@ -5,7 +5,7 @@ use parser::Spanning;
|
|||
use validation::{Visitor, ValidatorContext};
|
||||
|
||||
pub struct ArgumentsOfCorrectType<'a> {
|
||||
current_args: Option<&'a Vec<Argument>>,
|
||||
current_args: Option<&'a Vec<Argument<'a>>>,
|
||||
}
|
||||
|
||||
pub fn factory<'a>() -> ArgumentsOfCorrectType<'a> {
|
||||
|
|
|
@ -10,7 +10,7 @@ enum ArgumentPosition<'a> {
|
|||
}
|
||||
|
||||
pub struct KnownArgumentNames<'a> {
|
||||
current_args: Option<(ArgumentPosition<'a>, &'a Vec<Argument>)>,
|
||||
current_args: Option<(ArgumentPosition<'a>, &'a Vec<Argument<'a>>)>,
|
||||
}
|
||||
|
||||
pub fn factory<'a>() -> KnownArgumentNames<'a> {
|
||||
|
|
|
@ -14,7 +14,7 @@ struct Conflict(ConflictReason, Vec<SourcePosition>, Vec<SourcePosition>);
|
|||
struct ConflictReason(String, ConflictReasonMessage);
|
||||
|
||||
#[derive(Debug)]
|
||||
struct AstAndDef<'a>(Option<&'a str>, &'a Spanning<Field>, Option<&'a FieldType>);
|
||||
struct AstAndDef<'a>(Option<&'a str>, &'a Spanning<Field>, Option<&'a FieldType<'a>>);
|
||||
|
||||
type AstAndDefCollection<'a> = OrderedMap<&'a str, Vec<AstAndDef<'a>>>;
|
||||
|
||||
|
@ -1171,11 +1171,13 @@ mod tests {
|
|||
Some("SomeBox")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_interface_type::<Self>()(&[
|
||||
registry.field::<Option<SomeBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<SomeBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
];
|
||||
|
||||
registry.build_interface_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -1187,15 +1189,17 @@ mod tests {
|
|||
Some("StringBox")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("scalar"),
|
||||
registry.field::<Option<StringBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
registry.field::<Option<Vec<Option<StringBox>>>>("listStringBox"),
|
||||
registry.field::<Option<StringBox>>("stringBox"),
|
||||
registry.field::<Option<IntBox>>("intBox"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("scalar"),
|
||||
registry.field::<Option<StringBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
registry.field::<Option<Vec<Option<StringBox>>>>("listStringBox"),
|
||||
registry.field::<Option<StringBox>>("stringBox"),
|
||||
registry.field::<Option<IntBox>>("intBox"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<SomeBox>(),
|
||||
])
|
||||
|
@ -1210,15 +1214,17 @@ mod tests {
|
|||
Some("IntBox")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<i64>>("scalar"),
|
||||
registry.field::<Option<IntBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
registry.field::<Option<Vec<Option<StringBox>>>>("listStringBox"),
|
||||
registry.field::<Option<StringBox>>("stringBox"),
|
||||
registry.field::<Option<IntBox>>("intBox"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<i64>>("scalar"),
|
||||
registry.field::<Option<IntBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
registry.field::<Option<Vec<Option<StringBox>>>>("listStringBox"),
|
||||
registry.field::<Option<StringBox>>("stringBox"),
|
||||
registry.field::<Option<IntBox>>("intBox"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<SomeBox>(),
|
||||
])
|
||||
|
@ -1233,10 +1239,12 @@ mod tests {
|
|||
Some("NonNullStringBox1")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_interface_type::<Self>()(&[
|
||||
registry.field::<String>("scalar"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<String>("scalar"),
|
||||
];
|
||||
|
||||
registry.build_interface_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -1248,12 +1256,14 @@ mod tests {
|
|||
Some("NonNullStringBox1Impl")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<String>("scalar"),
|
||||
registry.field::<Option<SomeBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<String>("scalar"),
|
||||
registry.field::<Option<SomeBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<NonNullStringBox1>(),
|
||||
registry.get_type::<SomeBox>(),
|
||||
|
@ -1269,10 +1279,12 @@ mod tests {
|
|||
Some("NonNullStringBox2")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_interface_type::<Self>()(&[
|
||||
registry.field::<String>("scalar"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<String>("scalar"),
|
||||
];
|
||||
|
||||
registry.build_interface_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -1284,12 +1296,14 @@ mod tests {
|
|||
Some("NonNullStringBox2Impl")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<String>("scalar"),
|
||||
registry.field::<Option<SomeBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<String>("scalar"),
|
||||
registry.field::<Option<SomeBox>>("deepBox"),
|
||||
registry.field::<Option<String>>("unrelatedField"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<NonNullStringBox2>(),
|
||||
registry.get_type::<SomeBox>(),
|
||||
|
@ -1305,11 +1319,13 @@ mod tests {
|
|||
Some("Node")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<ID>>("id"),
|
||||
registry.field::<Option<String>>("name"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<ID>>("id"),
|
||||
registry.field::<Option<String>>("name"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -1321,10 +1337,12 @@ mod tests {
|
|||
Some("Edge")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<Node>>("node"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<Node>>("node"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -1336,10 +1354,12 @@ mod tests {
|
|||
Some("Connection")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<Vec<Option<Edge>>>>("edges"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<Vec<Option<Edge>>>>("edges"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -1351,16 +1371,17 @@ mod tests {
|
|||
Some("QueryRoot")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.get_type::<IntBox>();
|
||||
registry.get_type::<StringBox>();
|
||||
registry.get_type::<NonNullStringBox1Impl>();
|
||||
registry.get_type::<NonNullStringBox2Impl>();
|
||||
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<SomeBox>>("someBox"),
|
||||
registry.field::<Option<Connection>>("connection"),
|
||||
])
|
||||
let fields = &[
|
||||
registry.field::<Option<SomeBox>>("someBox"),
|
||||
registry.field::<Option<Connection>>("connection"),
|
||||
];
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use parser::Spanning;
|
|||
use schema::meta::MetaType;
|
||||
|
||||
pub struct PossibleFragmentSpreads<'a> {
|
||||
fragment_types: HashMap<&'a str, &'a MetaType>,
|
||||
fragment_types: HashMap<&'a str, &'a MetaType<'a>>,
|
||||
}
|
||||
|
||||
pub fn factory<'a>() -> PossibleFragmentSpreads<'a> {
|
||||
|
|
|
@ -12,8 +12,8 @@ pub enum Scope<'a> {
|
|||
|
||||
pub struct VariableInAllowedPosition<'a> {
|
||||
spreads: HashMap<Scope<'a>, HashSet<&'a str>>,
|
||||
variable_usages: HashMap<Scope<'a>, Vec<(Spanning<&'a String>, Type)>>,
|
||||
variable_defs: HashMap<Scope<'a>, Vec<&'a (Spanning<String>, VariableDefinition)>>,
|
||||
variable_usages: HashMap<Scope<'a>, Vec<(Spanning<&'a String>, Type<'a>)>>,
|
||||
variable_defs: HashMap<Scope<'a>, Vec<&'a (Spanning<String>, VariableDefinition<'a>)>>,
|
||||
current_scope: Option<Scope<'a>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -58,11 +58,13 @@ impl GraphQLType for Being {
|
|||
Some("Being")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_interface_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields =&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
];
|
||||
|
||||
registry.build_interface_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -74,11 +76,13 @@ impl GraphQLType for Pet {
|
|||
Some("Pet")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_interface_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
];
|
||||
|
||||
registry.build_interface_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -90,11 +94,13 @@ impl GraphQLType for Canine {
|
|||
Some("Canine")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_interface_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
];
|
||||
|
||||
registry.build_interface_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -106,13 +112,12 @@ impl GraphQLType for DogCommand {
|
|||
Some("DogCommand")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_enum_type::<Self>()(&[
|
||||
EnumValue::new("SIT"),
|
||||
EnumValue::new("HEEL"),
|
||||
EnumValue::new("DOWN"),
|
||||
])
|
||||
.into_meta()
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_enum_type::<Self>(&[
|
||||
EnumValue::new("SIT"),
|
||||
EnumValue::new("HEEL"),
|
||||
EnumValue::new("DOWN"),
|
||||
]).into_meta()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,21 +139,23 @@ impl GraphQLType for Dog {
|
|||
Some("Dog")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<String>>("nickname"),
|
||||
registry.field::<Option<i64>>("barkVolume"),
|
||||
registry.field::<Option<bool>>("barks"),
|
||||
registry.field::<Option<bool>>("doesKnowCommand")
|
||||
.argument(registry.arg::<Option<DogCommand>>("dogCommand")),
|
||||
registry.field::<Option<bool>>("isHousetrained")
|
||||
.argument(registry.arg_with_default("atOtherHomes", &true)),
|
||||
registry.field::<Option<bool>>("isAtLocation")
|
||||
.argument(registry.arg::<Option<i64>>("x"))
|
||||
.argument(registry.arg::<Option<i64>>("y")),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<String>>("nickname"),
|
||||
registry.field::<Option<i64>>("barkVolume"),
|
||||
registry.field::<Option<bool>>("barks"),
|
||||
registry.field::<Option<bool>>("doesKnowCommand")
|
||||
.argument(registry.arg::<Option<DogCommand>>("dogCommand")),
|
||||
registry.field::<Option<bool>>("isHousetrained")
|
||||
.argument(registry.arg_with_default("atOtherHomes", &true)),
|
||||
registry.field::<Option<bool>>("isAtLocation")
|
||||
.argument(registry.arg::<Option<i64>>("x"))
|
||||
.argument(registry.arg::<Option<i64>>("y")),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<Being>(),
|
||||
registry.get_type::<Pet>(),
|
||||
|
@ -165,13 +172,13 @@ impl GraphQLType for FurColor {
|
|||
Some("FurColor")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_enum_type::<Self>()(&[
|
||||
EnumValue::new("BROWN"),
|
||||
EnumValue::new("BLACK"),
|
||||
EnumValue::new("TAN"),
|
||||
EnumValue::new("SPOTTED"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
registry.build_enum_type::<Self>(&[
|
||||
EnumValue::new("BROWN"),
|
||||
EnumValue::new("BLACK"),
|
||||
EnumValue::new("TAN"),
|
||||
EnumValue::new("SPOTTED"),
|
||||
])
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -195,15 +202,17 @@ impl GraphQLType for Cat {
|
|||
Some("Cat")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<String>>("nickname"),
|
||||
registry.field::<Option<bool>>("meows"),
|
||||
registry.field::<Option<i64>>("meowVolume"),
|
||||
registry.field::<Option<FurColor>>("furColor"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<String>>("nickname"),
|
||||
registry.field::<Option<bool>>("meows"),
|
||||
registry.field::<Option<i64>>("meowVolume"),
|
||||
registry.field::<Option<FurColor>>("furColor"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<Being>(),
|
||||
registry.get_type::<Pet>(),
|
||||
|
@ -219,11 +228,13 @@ impl GraphQLType for CatOrDog {
|
|||
Some("CatOrDog")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_union_type::<Self>()(&[
|
||||
registry.get_type::<Cat>(),
|
||||
registry.get_type::<Dog>(),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let types = &[
|
||||
registry.get_type::<Cat>(),
|
||||
registry.get_type::<Dog>(),
|
||||
];
|
||||
|
||||
registry.build_union_type::<Self>(types)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -235,10 +246,12 @@ impl GraphQLType for Intelligent {
|
|||
Some("Intelligent")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_interface_type::<Self>()(&[
|
||||
registry.field::<Option<i64>>("iq"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<i64>>("iq"),
|
||||
];
|
||||
|
||||
registry.build_interface_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -250,14 +263,15 @@ impl GraphQLType for Human {
|
|||
Some("Human")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<Vec<Option<Pet>>>>("pets"),
|
||||
registry.field::<Option<Vec<Human>>>("relatives"),
|
||||
registry.field::<Option<i64>>("iq"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<Vec<Option<Pet>>>>("pets"),
|
||||
registry.field::<Option<Vec<Human>>>("relatives"),
|
||||
registry.field::<Option<i64>>("iq"),
|
||||
];
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<Being>(),
|
||||
registry.get_type::<Intelligent>(),
|
||||
|
@ -273,13 +287,15 @@ impl GraphQLType for Alien {
|
|||
Some("Alien")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<i64>>("iq"),
|
||||
registry.field::<Option<i64>>("numEyes"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("name")
|
||||
.argument(registry.arg::<Option<bool>>("surname")),
|
||||
registry.field::<Option<i64>>("iq"),
|
||||
registry.field::<Option<i64>>("numEyes"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.interfaces(&[
|
||||
registry.get_type::<Being>(),
|
||||
registry.get_type::<Intelligent>(),
|
||||
|
@ -295,11 +311,13 @@ impl GraphQLType for DogOrHuman {
|
|||
Some("DogOrHuman")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_union_type::<Self>()(&[
|
||||
registry.get_type::<Dog>(),
|
||||
registry.get_type::<Human>(),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let types = &[
|
||||
registry.get_type::<Dog>(),
|
||||
registry.get_type::<Human>(),
|
||||
];
|
||||
|
||||
registry.build_union_type::<Self>(types)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -311,11 +329,13 @@ impl GraphQLType for HumanOrAlien {
|
|||
Some("HumanOrAlien")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_union_type::<Self>()(&[
|
||||
registry.get_type::<Human>(),
|
||||
registry.get_type::<Alien>(),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let types = &[
|
||||
registry.get_type::<Human>(),
|
||||
registry.get_type::<Alien>(),
|
||||
];
|
||||
|
||||
registry.build_union_type::<Self>(types)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -327,14 +347,16 @@ impl GraphQLType for ComplexInput {
|
|||
Some("ComplexInput")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_input_object_type::<Self>()(&[
|
||||
registry.arg::<bool>("requiredField"),
|
||||
registry.arg::<Option<i64>>("intField"),
|
||||
registry.arg::<Option<String>>("stringField"),
|
||||
registry.arg::<Option<bool>>("booleanField"),
|
||||
registry.arg::<Option<Vec<Option<String>>>>("stringListField"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.arg::<bool>("requiredField"),
|
||||
registry.arg::<Option<i64>>("intField"),
|
||||
registry.arg::<Option<String>>("stringField"),
|
||||
registry.arg::<Option<bool>>("booleanField"),
|
||||
registry.arg::<Option<Vec<Option<String>>>>("stringListField"),
|
||||
];
|
||||
|
||||
registry.build_input_object_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -366,38 +388,40 @@ impl GraphQLType for ComplicatedArgs {
|
|||
Some("ComplicatedArgs")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<String>>("intArgField")
|
||||
.argument(registry.arg::<Option<i64>>("intArg")),
|
||||
registry.field::<Option<String>>("nonNullIntArgField")
|
||||
.argument(registry.arg::<i64>("nonNullIntArg")),
|
||||
registry.field::<Option<String>>("stringArgField")
|
||||
.argument(registry.arg::<Option<String>>("stringArg")),
|
||||
registry.field::<Option<String>>("booleanArgField")
|
||||
.argument(registry.arg::<Option<bool>>("booleanArg")),
|
||||
registry.field::<Option<String>>("enumArgField")
|
||||
.argument(registry.arg::<Option<FurColor>>("enumArg")),
|
||||
registry.field::<Option<String>>("floatArgField")
|
||||
.argument(registry.arg::<Option<f64>>("floatArg")),
|
||||
registry.field::<Option<String>>("idArgField")
|
||||
.argument(registry.arg::<Option<ID>>("idArg")),
|
||||
registry.field::<Option<String>>("stringListArgField")
|
||||
.argument(registry.arg::<Option<Vec<Option<String>>>>("stringListArg")),
|
||||
registry.field::<Option<String>>("complexArgField")
|
||||
.argument(registry.arg::<Option<ComplexInput>>("complexArg")),
|
||||
registry.field::<Option<String>>("multipleReqs")
|
||||
.argument(registry.arg::<i64>("req1"))
|
||||
.argument(registry.arg::<i64>("req2")),
|
||||
registry.field::<Option<String>>("multipleOpts")
|
||||
.argument(registry.arg_with_default("opt1", &0i64))
|
||||
.argument(registry.arg_with_default("opt2", &0i64)),
|
||||
registry.field::<Option<String>>("multipleOptAndReq")
|
||||
.argument(registry.arg::<i64>("req1"))
|
||||
.argument(registry.arg::<i64>("req2"))
|
||||
.argument(registry.arg_with_default("opt1", &0i64))
|
||||
.argument(registry.arg_with_default("opt2", &0i64)),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<String>>("intArgField")
|
||||
.argument(registry.arg::<Option<i64>>("intArg")),
|
||||
registry.field::<Option<String>>("nonNullIntArgField")
|
||||
.argument(registry.arg::<i64>("nonNullIntArg")),
|
||||
registry.field::<Option<String>>("stringArgField")
|
||||
.argument(registry.arg::<Option<String>>("stringArg")),
|
||||
registry.field::<Option<String>>("booleanArgField")
|
||||
.argument(registry.arg::<Option<bool>>("booleanArg")),
|
||||
registry.field::<Option<String>>("enumArgField")
|
||||
.argument(registry.arg::<Option<FurColor>>("enumArg")),
|
||||
registry.field::<Option<String>>("floatArgField")
|
||||
.argument(registry.arg::<Option<f64>>("floatArg")),
|
||||
registry.field::<Option<String>>("idArgField")
|
||||
.argument(registry.arg::<Option<ID>>("idArg")),
|
||||
registry.field::<Option<String>>("stringListArgField")
|
||||
.argument(registry.arg::<Option<Vec<Option<String>>>>("stringListArg")),
|
||||
registry.field::<Option<String>>("complexArgField")
|
||||
.argument(registry.arg::<Option<ComplexInput>>("complexArg")),
|
||||
registry.field::<Option<String>>("multipleReqs")
|
||||
.argument(registry.arg::<i64>("req1"))
|
||||
.argument(registry.arg::<i64>("req2")),
|
||||
registry.field::<Option<String>>("multipleOpts")
|
||||
.argument(registry.arg_with_default("opt1", &0i64))
|
||||
.argument(registry.arg_with_default("opt2", &0i64)),
|
||||
registry.field::<Option<String>>("multipleOptAndReq")
|
||||
.argument(registry.arg::<i64>("req1"))
|
||||
.argument(registry.arg::<i64>("req2"))
|
||||
.argument(registry.arg_with_default("opt1", &0i64))
|
||||
.argument(registry.arg_with_default("opt2", &0i64)),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
@ -409,19 +433,21 @@ impl GraphQLType for QueryRoot {
|
|||
Some("QueryRoot")
|
||||
}
|
||||
|
||||
fn meta(registry: &mut Registry) -> MetaType {
|
||||
registry.build_object_type::<Self>()(&[
|
||||
registry.field::<Option<Human>>("human")
|
||||
.argument(registry.arg::<Option<ID>>("id")),
|
||||
registry.field::<Option<Alien>>("alien"),
|
||||
registry.field::<Option<Dog>>("dog"),
|
||||
registry.field::<Option<Cat>>("cat"),
|
||||
registry.field::<Option<Pet>>("pet"),
|
||||
registry.field::<Option<CatOrDog>>("catOrDog"),
|
||||
registry.field::<Option<DogOrHuman>>("dorOrHuman"),
|
||||
registry.field::<Option<HumanOrAlien>>("humanOrAlien"),
|
||||
registry.field::<Option<ComplicatedArgs>>("complicatedArgs"),
|
||||
])
|
||||
fn meta<'r>(registry: &mut Registry<'r>) -> MetaType<'r> {
|
||||
let fields = &[
|
||||
registry.field::<Option<Human>>("human")
|
||||
.argument(registry.arg::<Option<ID>>("id")),
|
||||
registry.field::<Option<Alien>>("alien"),
|
||||
registry.field::<Option<Dog>>("dog"),
|
||||
registry.field::<Option<Cat>>("cat"),
|
||||
registry.field::<Option<Pet>>("pet"),
|
||||
registry.field::<Option<CatOrDog>>("catOrDog"),
|
||||
registry.field::<Option<DogOrHuman>>("dorOrHuman"),
|
||||
registry.field::<Option<HumanOrAlien>>("humanOrAlien"),
|
||||
registry.field::<Option<ComplicatedArgs>>("complicatedArgs"),
|
||||
];
|
||||
|
||||
registry.build_object_type::<Self>(fields)
|
||||
.into_meta()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,14 @@ fn visit_definitions<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'
|
|||
let def_type = match *def {
|
||||
Definition::Fragment(Spanning {
|
||||
item: Fragment { type_condition: Spanning { item: ref name, .. }, .. }, .. }) =>
|
||||
Some(Type::NonNullNamed(name.to_owned())),
|
||||
Some(Type::NonNullNamed(name)),
|
||||
Definition::Operation(Spanning {
|
||||
item: Operation { operation_type: OperationType::Query, .. }, .. }) =>
|
||||
Some(Type::NonNullNamed(ctx.schema.concrete_query_type().name().unwrap().to_owned())),
|
||||
Some(Type::NonNullNamed(ctx.schema.concrete_query_type().name().unwrap())),
|
||||
Definition::Operation(Spanning {
|
||||
item: Operation { operation_type: OperationType::Mutation, .. }, .. }) =>
|
||||
ctx.schema.concrete_mutation_type()
|
||||
.map(|t| Type::NonNullNamed(t.name().unwrap().to_owned())),
|
||||
.map(|t| Type::NonNullNamed(t.name().unwrap())),
|
||||
};
|
||||
|
||||
ctx.with_pushed_type(def_type.as_ref(), |ctx| {
|
||||
|
@ -93,7 +93,7 @@ fn visit_directives<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_arguments<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a>, meta_args: &Option<&Vec<Argument>>, arguments: &'a Option<Spanning<Arguments>>) {
|
||||
fn visit_arguments<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a>, meta_args: &Option<&Vec<Argument<'a>>>, arguments: &'a Option<Spanning<Arguments>>) {
|
||||
if let Some(ref arguments) = *arguments {
|
||||
for argument in arguments.item.iter() {
|
||||
let arg_type = meta_args
|
||||
|
@ -161,7 +161,7 @@ fn visit_fragment_spread<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorConte
|
|||
}
|
||||
|
||||
fn visit_inline_fragment<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a>, fragment: &'a Spanning<InlineFragment>) {
|
||||
let type_name = fragment.item.type_condition.clone().map(|s| s.item);
|
||||
let type_name = fragment.item.type_condition.as_ref().map(|s| s.item.as_str());
|
||||
|
||||
let mut visit_fn = move |ctx: &mut ValidatorContext<'a>| {
|
||||
v.enter_inline_fragment(ctx, fragment);
|
||||
|
|
Loading…
Reference in a new issue