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