diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index 37f95821..cbcb0091 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -353,7 +353,7 @@ where } /// View the underlying string value, if present. - pub fn as_string_value<'a>(&'a self) -> Option<&'a str> { + pub fn as_string_value(&self) -> Option<&str> { self.as_scalar_value().and_then(|s| s.as_str()) } diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index ad94b360..cb5593b3 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -620,7 +620,7 @@ where self.field_path.construct_path(&mut path); ExecutionError { - location: self.location().clone(), + location: *self.location(), path, error, } diff --git a/juniper/src/schema/model.rs b/juniper/src/schema/model.rs index 6e87bee9..9eb74767 100644 --- a/juniper/src/schema/model.rs +++ b/juniper/src/schema/model.rs @@ -139,6 +139,7 @@ where } impl<'a, S> SchemaType<'a, S> { + /// Create a new schema. pub fn new( query_info: &QueryT::TypeInfo, mutation_info: &MutationT::TypeInfo, @@ -218,14 +219,17 @@ impl<'a, S> SchemaType<'a, S> { } } + /// Add a directive like `skip` or `include`. pub fn add_directive(&mut self, directive: DirectiveType<'a, S>) { self.directives.insert(directive.name.clone(), directive); } + /// Get a type by name. pub fn type_by_name(&self, name: &str) -> Option> { self.types.get(name).map(|t| TypeType::Concrete(t)) } + /// Get a concrete type by name. pub fn concrete_type_by_name(&self, name: &str) -> Option<&MetaType> { self.types.get(name) } @@ -239,6 +243,7 @@ impl<'a, S> SchemaType<'a, S> { } } + /// Get the query type from the schema. pub fn query_type(&self) -> TypeType { TypeType::Concrete( self.types @@ -247,12 +252,14 @@ impl<'a, S> SchemaType<'a, S> { ) } + /// Get the concrete query type from the schema. pub fn concrete_query_type(&self) -> &MetaType { self.types .get(&self.query_type_name) .expect("Query type does not exist in schema") } + /// Get the mutation type from the schema. pub fn mutation_type(&self) -> Option> { if let Some(ref mutation_type_name) = self.mutation_type_name { Some( @@ -264,6 +271,7 @@ impl<'a, S> SchemaType<'a, S> { } } + /// Get the concrete mutation type from the schema. pub fn concrete_mutation_type(&self) -> Option<&MetaType> { self.mutation_type_name.as_ref().map(|name| { self.concrete_type_by_name(name) @@ -271,6 +279,7 @@ impl<'a, S> SchemaType<'a, S> { }) } + /// Get the subscription type. pub fn subscription_type(&self) -> Option> { if let Some(ref subscription_type_name) = self.subscription_type_name { Some( @@ -282,6 +291,7 @@ impl<'a, S> SchemaType<'a, S> { } } + /// Get the concrete subscription type. pub fn concrete_subscription_type(&self) -> Option<&MetaType> { self.subscription_type_name.as_ref().map(|name| { self.concrete_type_by_name(name) @@ -289,14 +299,17 @@ impl<'a, S> SchemaType<'a, S> { }) } + /// Get a list of types. pub fn type_list(&self) -> Vec> { self.types.values().map(|t| TypeType::Concrete(t)).collect() } + /// Get a list of concrete types. pub fn concrete_type_list(&self) -> Vec<&MetaType> { self.types.values().collect() } + /// Make a type. pub fn make_type(&self, t: &Type) -> TypeType { match *t { Type::NonNullNamed(ref n) => TypeType::NonNull(Box::new( @@ -310,14 +323,17 @@ impl<'a, S> SchemaType<'a, S> { } } + /// Get a list of directives. pub fn directive_list(&self) -> Vec<&DirectiveType> { self.directives.values().collect() } + /// Get directive by name. pub fn directive_by_name(&self, name: &str) -> Option<&DirectiveType> { self.directives.get(name) } + /// Determine if there is an overlap between types. pub fn type_overlap(&self, t1: &MetaType, t2: &MetaType) -> bool { if (t1 as *const MetaType) == (t2 as *const MetaType) { return true; @@ -334,6 +350,7 @@ impl<'a, S> SchemaType<'a, S> { } } + /// A list of possible typeees for a given type. pub fn possible_types(&self, t: &MetaType) -> Vec<&MetaType> { match *t { MetaType::Union(UnionMeta { @@ -357,6 +374,7 @@ impl<'a, S> SchemaType<'a, S> { } } + /// If the abstract type is possible. pub fn is_possible_type( &self, abstract_type: &MetaType, @@ -367,6 +385,7 @@ impl<'a, S> SchemaType<'a, S> { .any(|t| (t as *const MetaType) == (possible_type as *const MetaType)) } + /// If the type is a subtype of another type. pub fn is_subtype<'b>(&self, sub_type: &Type<'b>, super_type: &Type<'b>) -> bool { use crate::ast::Type::*; @@ -389,6 +408,7 @@ impl<'a, S> SchemaType<'a, S> { } } + /// If the type is a named subtype. pub fn is_named_subtype(&self, sub_type_name: &str, super_type_name: &str) -> bool { if sub_type_name == super_type_name { true diff --git a/juniper/src/types/scalars.rs b/juniper/src/types/scalars.rs index c10e71b9..fa260c53 100644 --- a/juniper/src/types/scalars.rs +++ b/juniper/src/types/scalars.rs @@ -340,6 +340,7 @@ where /// /// If you instantiate `RootNode` with this as the subscription, /// no subscriptions will be generated for the schema. +#[derive(Default)] pub struct EmptySubscription { phantom: PhantomData, } diff --git a/juniper/src/types/subscriptions.rs b/juniper/src/types/subscriptions.rs index 3635307c..5b6ccc56 100644 --- a/juniper/src/types/subscriptions.rs +++ b/juniper/src/types/subscriptions.rs @@ -364,22 +364,20 @@ where } else if let Err(e) = sub_result { sub_exec.push_error_at(e, start_pos.clone()); } - } else { - if let Some(type_name) = meta_type.name() { - let sub_result = instance - .resolve_into_type_stream(info, type_name, &sub_exec) - .await; + } else if let Some(type_name) = meta_type.name() { + let sub_result = instance + .resolve_into_type_stream(info, type_name, &sub_exec) + .await; - if let Ok(Value::Object(obj)) = sub_result { - for (k, v) in obj { - merge_key_into(&mut object, &k, v); - } - } else if let Err(e) = sub_result { - sub_exec.push_error_at(e, start_pos.clone()); + if let Ok(Value::Object(obj)) = sub_result { + for (k, v) in obj { + merge_key_into(&mut object, &k, v); } - } else { - return Value::Null; + } else if let Err(e) = sub_result { + sub_exec.push_error_at(e, start_pos.clone()); } + } else { + return Value::Null; } } } diff --git a/juniper/src/validation/rules/variables_in_allowed_position.rs b/juniper/src/validation/rules/variables_in_allowed_position.rs index d1463991..9e7e3fc3 100644 --- a/juniper/src/validation/rules/variables_in_allowed_position.rs +++ b/juniper/src/validation/rules/variables_in_allowed_position.rs @@ -37,7 +37,7 @@ impl<'a, S: Debug> VariableInAllowedPosition<'a, S> { fn collect_incorrect_usages( &self, from: &Scope<'a>, - var_defs: &Vec<&'a (Spanning<&'a str>, VariableDefinition)>, + var_defs: &[&'a (Spanning<&'a str>, VariableDefinition)], ctx: &mut ValidatorContext<'a, S>, visited: &mut HashSet>, ) { diff --git a/juniper_codegen/src/lib.rs b/juniper_codegen/src/lib.rs index 25736704..562e4a2f 100644 --- a/juniper_codegen/src/lib.rs +++ b/juniper_codegen/src/lib.rs @@ -388,15 +388,13 @@ pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenSt /// A proc macro for defining a GraphQL subscription. #[proc_macro_attribute] pub fn graphql_subscription(args: TokenStream, input: TokenStream) -> TokenStream { - let gen = impl_object::build_subscription(args, input, false); - gen.into() + impl_object::build_subscription(args, input, false) } #[doc(hidden)] #[proc_macro_attribute] pub fn graphql_subscription_internal(args: TokenStream, input: TokenStream) -> TokenStream { - let gen = impl_object::build_subscription(args, input, true); - gen.into() + impl_object::build_subscription(args, input, true) } #[proc_macro_attribute] diff --git a/juniper_subscriptions/src/lib.rs b/juniper_subscriptions/src/lib.rs index 111404d9..ff6666e1 100644 --- a/juniper_subscriptions/src/lib.rs +++ b/juniper_subscriptions/src/lib.rs @@ -11,7 +11,7 @@ #![deny(warnings)] #![doc(html_root_url = "https://docs.rs/juniper_subscriptions/0.14.2")] -use std::{borrow::BorrowMut as _, iter::FromIterator, pin::Pin}; +use std::{iter::FromIterator, pin::Pin}; use futures::{task::Poll, Stream}; use juniper::{ @@ -197,12 +197,11 @@ where // TODO: iterate over i and (ref field_name, ref val) once // [this RFC](https://github.com/rust-lang/rust/issues/68354) // is implemented - for i in 0..obj_len { + for ready in ready_vec.iter_mut().take(obj_len) { let (field_name, val) = match obj_iterator.next() { Some(v) => v, None => break, }; - let ready = ready_vec[i].borrow_mut(); if ready.is_some() { continue; diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index 621ae385..69e5ed7d 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -343,7 +343,7 @@ where }; let get_filter = warp::get() - .and(context_extractor.clone()) + .and(context_extractor) .and(warp::filters::query::query()) .and_then(handle_get_request);