Skip to content

Commit

Permalink
Merge branch 'master' into accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor-Savu authored Apr 4, 2020
2 parents 25d26aa + adc8d7b commit 98e0ea9
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 138 deletions.
23 changes: 6 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,9 @@ jobs:
profile: minimal
override: true

- name: Install cargo-make (Linux)
if: runner.os == 'Linux'
run: |
_build/cargo-make.sh "0.20.0" "x86_64-unknown-linux-musl"
- name: Install cargo-make (macOS)
if: runner.os == 'macOS'
run: |
_build/cargo-make.sh "0.20.0" "x86_64-apple-darwin"
- name: Install cargo-make (Windows)
if: runner.os == 'Windows'
run: |
_build\cargo-make.ps1 -version "0.20.0" -target "x86_64-pc-windows-msvc"
- uses: davidB/rust-cargo-make@v1
with:
version: '0.20.0'

- name: Build and run tests
env:
Expand Down Expand Up @@ -127,9 +116,9 @@ jobs:
profile: minimal
override: true

- name: Install cargo-make
run: |
_build/cargo-make.sh "0.20.0" "x86_64-unknown-linux-musl"
- uses: davidB/rust-cargo-make@v1
with:
version: '0.20.0'

- name: Install cargo-release
uses: actions-rs/cargo@v1
Expand Down
7 changes: 3 additions & 4 deletions examples/warp_subscriptions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ serde_json = "1.0"
tokio = { version = "0.2", features = ["rt-core", "macros"] }
warp = "0.2.1"

# TODO#433: get crates from GitHub
juniper = { path = "../../juniper" }
juniper_subscriptions = { path = "../../juniper_subscriptions"}
juniper_warp = { path = "../../juniper_warp", features = ["subscriptions"] }
juniper = { git = "https://github.com/graphql-rust/juniper" }
juniper_subscriptions = { git = "https://github.com/graphql-rust/juniper" }
juniper_warp = { git = "https://github.com/graphql-rust/juniper", features = ["subscriptions"] }
16 changes: 11 additions & 5 deletions examples/warp_subscriptions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,20 @@ async fn main() {
ctx: Context,
coordinator: Arc<Coordinator<'static, _, _, _, _, _>>| {
ws.on_upgrade(|websocket| -> Pin<Box<dyn Future<Output = ()> + Send>> {
graphql_subscriptions(websocket, coordinator, ctx).boxed()
graphql_subscriptions(websocket, coordinator, ctx)
.map(|r| {
if let Err(e) = r {
println!("Websocket error: {}", e);
}
})
.boxed()
})
},
))
.map(|reply| {
// TODO#584: remove this workaround
warp::reply::with_header(reply, "Sec-WebSocket-Protocol", "graphql-ws")
})
.map(|reply| {
// TODO#584: remove this workaround
warp::reply::with_header(reply, "Sec-WebSocket-Protocol", "graphql-ws")
})
.or(warp::post()
.and(warp::path("graphql"))
.and(qm_graphql_filter))
Expand Down
2 changes: 1 addition & 1 deletion juniper/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
2 changes: 1 addition & 1 deletion juniper/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ where
self.field_path.construct_path(&mut path);

ExecutionError {
location: self.location().clone(),
location: *self.location(),
path,
error,
}
Expand Down
20 changes: 20 additions & 0 deletions juniper/src/schema/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ where
}

impl<'a, S> SchemaType<'a, S> {
/// Create a new schema.
pub fn new<QueryT, MutationT, SubscriptionT>(
query_info: &QueryT::TypeInfo,
mutation_info: &MutationT::TypeInfo,
Expand Down Expand Up @@ -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<TypeType<S>> {
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<S>> {
self.types.get(name)
}
Expand All @@ -239,6 +243,7 @@ impl<'a, S> SchemaType<'a, S> {
}
}

/// Get the query type from the schema.
pub fn query_type(&self) -> TypeType<S> {
TypeType::Concrete(
self.types
Expand All @@ -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<S> {
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<TypeType<S>> {
if let Some(ref mutation_type_name) = self.mutation_type_name {
Some(
Expand All @@ -264,13 +271,15 @@ impl<'a, S> SchemaType<'a, S> {
}
}

/// Get the concrete mutation type from the schema.
pub fn concrete_mutation_type(&self) -> Option<&MetaType<S>> {
self.mutation_type_name.as_ref().map(|name| {
self.concrete_type_by_name(name)
.expect("Mutation type does not exist in schema")
})
}

/// Get the subscription type.
pub fn subscription_type(&self) -> Option<TypeType<S>> {
if let Some(ref subscription_type_name) = self.subscription_type_name {
Some(
Expand All @@ -282,21 +291,25 @@ impl<'a, S> SchemaType<'a, S> {
}
}

/// Get the concrete subscription type.
pub fn concrete_subscription_type(&self) -> Option<&MetaType<S>> {
self.subscription_type_name.as_ref().map(|name| {
self.concrete_type_by_name(name)
.expect("Subscription type does not exist in schema")
})
}

/// Get a list of types.
pub fn type_list(&self) -> Vec<TypeType<S>> {
self.types.values().map(|t| TypeType::Concrete(t)).collect()
}

/// Get a list of concrete types.
pub fn concrete_type_list(&self) -> Vec<&MetaType<S>> {
self.types.values().collect()
}

/// Make a type.
pub fn make_type(&self, t: &Type) -> TypeType<S> {
match *t {
Type::NonNullNamed(ref n) => TypeType::NonNull(Box::new(
Expand All @@ -310,14 +323,17 @@ impl<'a, S> SchemaType<'a, S> {
}
}

/// Get a list of directives.
pub fn directive_list(&self) -> Vec<&DirectiveType<S>> {
self.directives.values().collect()
}

/// Get directive by name.
pub fn directive_by_name(&self, name: &str) -> Option<&DirectiveType<S>> {
self.directives.get(name)
}

/// Determine if there is an overlap between types.
pub fn type_overlap(&self, t1: &MetaType<S>, t2: &MetaType<S>) -> bool {
if (t1 as *const MetaType<S>) == (t2 as *const MetaType<S>) {
return true;
Expand All @@ -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<S>) -> Vec<&MetaType<S>> {
match *t {
MetaType::Union(UnionMeta {
Expand All @@ -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<S>,
Expand All @@ -367,6 +385,7 @@ impl<'a, S> SchemaType<'a, S> {
.any(|t| (t as *const MetaType<S>) == (possible_type as *const MetaType<S>))
}

/// 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::*;

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions juniper/src/types/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
phantom: PhantomData<T>,
}
Expand Down
26 changes: 12 additions & 14 deletions juniper/src/types/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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());
} 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 {
return Value::Null;
} else if let Err(e) = sub_result {
sub_exec.push_error_at(e, start_pos.clone());
}
} else {
return Value::Null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>)>,
var_defs: &[&'a (Spanning<&'a str>, VariableDefinition<S>)],
ctx: &mut ValidatorContext<'a, S>,
visited: &mut HashSet<Scope<'a>>,
) {
Expand Down
6 changes: 2 additions & 4 deletions juniper_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,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]
Expand Down
5 changes: 2 additions & 3 deletions juniper_subscriptions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 98e0ea9

Please sign in to comment.