Skip to content

Commit 98e0ea9

Browse files
authored
Merge branch 'master' into accessors
2 parents 25d26aa + adc8d7b commit 98e0ea9

File tree

12 files changed

+180
-138
lines changed

12 files changed

+180
-138
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,9 @@ jobs:
5454
profile: minimal
5555
override: true
5656

57-
- name: Install cargo-make (Linux)
58-
if: runner.os == 'Linux'
59-
run: |
60-
_build/cargo-make.sh "0.20.0" "x86_64-unknown-linux-musl"
61-
62-
- name: Install cargo-make (macOS)
63-
if: runner.os == 'macOS'
64-
run: |
65-
_build/cargo-make.sh "0.20.0" "x86_64-apple-darwin"
66-
67-
- name: Install cargo-make (Windows)
68-
if: runner.os == 'Windows'
69-
run: |
70-
_build\cargo-make.ps1 -version "0.20.0" -target "x86_64-pc-windows-msvc"
57+
- uses: davidB/rust-cargo-make@v1
58+
with:
59+
version: '0.20.0'
7160

7261
- name: Build and run tests
7362
env:
@@ -127,9 +116,9 @@ jobs:
127116
profile: minimal
128117
override: true
129118

130-
- name: Install cargo-make
131-
run: |
132-
_build/cargo-make.sh "0.20.0" "x86_64-unknown-linux-musl"
119+
- uses: davidB/rust-cargo-make@v1
120+
with:
121+
version: '0.20.0'
133122

134123
- name: Install cargo-release
135124
uses: actions-rs/cargo@v1

examples/warp_subscriptions/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ serde_json = "1.0"
1414
tokio = { version = "0.2", features = ["rt-core", "macros"] }
1515
warp = "0.2.1"
1616

17-
# TODO#433: get crates from GitHub
18-
juniper = { path = "../../juniper" }
19-
juniper_subscriptions = { path = "../../juniper_subscriptions"}
20-
juniper_warp = { path = "../../juniper_warp", features = ["subscriptions"] }
17+
juniper = { git = "https://github.com/graphql-rust/juniper" }
18+
juniper_subscriptions = { git = "https://github.com/graphql-rust/juniper" }
19+
juniper_warp = { git = "https://github.com/graphql-rust/juniper", features = ["subscriptions"] }

examples/warp_subscriptions/src/main.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,20 @@ async fn main() {
165165
ctx: Context,
166166
coordinator: Arc<Coordinator<'static, _, _, _, _, _>>| {
167167
ws.on_upgrade(|websocket| -> Pin<Box<dyn Future<Output = ()> + Send>> {
168-
graphql_subscriptions(websocket, coordinator, ctx).boxed()
168+
graphql_subscriptions(websocket, coordinator, ctx)
169+
.map(|r| {
170+
if let Err(e) = r {
171+
println!("Websocket error: {}", e);
172+
}
173+
})
174+
.boxed()
169175
})
170176
},
171177
))
172-
.map(|reply| {
173-
// TODO#584: remove this workaround
174-
warp::reply::with_header(reply, "Sec-WebSocket-Protocol", "graphql-ws")
175-
})
178+
.map(|reply| {
179+
// TODO#584: remove this workaround
180+
warp::reply::with_header(reply, "Sec-WebSocket-Protocol", "graphql-ws")
181+
})
176182
.or(warp::post()
177183
.and(warp::path("graphql"))
178184
.and(qm_graphql_filter))

juniper/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ where
353353
}
354354

355355
/// View the underlying string value, if present.
356-
pub fn as_string_value<'a>(&'a self) -> Option<&'a str> {
356+
pub fn as_string_value(&self) -> Option<&str> {
357357
self.as_scalar_value().and_then(|s| s.as_str())
358358
}
359359

juniper/src/executor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ where
620620
self.field_path.construct_path(&mut path);
621621

622622
ExecutionError {
623-
location: self.location().clone(),
623+
location: *self.location(),
624624
path,
625625
error,
626626
}

juniper/src/schema/model.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ where
139139
}
140140

141141
impl<'a, S> SchemaType<'a, S> {
142+
/// Create a new schema.
142143
pub fn new<QueryT, MutationT, SubscriptionT>(
143144
query_info: &QueryT::TypeInfo,
144145
mutation_info: &MutationT::TypeInfo,
@@ -218,14 +219,17 @@ impl<'a, S> SchemaType<'a, S> {
218219
}
219220
}
220221

222+
/// Add a directive like `skip` or `include`.
221223
pub fn add_directive(&mut self, directive: DirectiveType<'a, S>) {
222224
self.directives.insert(directive.name.clone(), directive);
223225
}
224226

227+
/// Get a type by name.
225228
pub fn type_by_name(&self, name: &str) -> Option<TypeType<S>> {
226229
self.types.get(name).map(|t| TypeType::Concrete(t))
227230
}
228231

232+
/// Get a concrete type by name.
229233
pub fn concrete_type_by_name(&self, name: &str) -> Option<&MetaType<S>> {
230234
self.types.get(name)
231235
}
@@ -239,6 +243,7 @@ impl<'a, S> SchemaType<'a, S> {
239243
}
240244
}
241245

246+
/// Get the query type from the schema.
242247
pub fn query_type(&self) -> TypeType<S> {
243248
TypeType::Concrete(
244249
self.types
@@ -247,12 +252,14 @@ impl<'a, S> SchemaType<'a, S> {
247252
)
248253
}
249254

255+
/// Get the concrete query type from the schema.
250256
pub fn concrete_query_type(&self) -> &MetaType<S> {
251257
self.types
252258
.get(&self.query_type_name)
253259
.expect("Query type does not exist in schema")
254260
}
255261

262+
/// Get the mutation type from the schema.
256263
pub fn mutation_type(&self) -> Option<TypeType<S>> {
257264
if let Some(ref mutation_type_name) = self.mutation_type_name {
258265
Some(
@@ -264,13 +271,15 @@ impl<'a, S> SchemaType<'a, S> {
264271
}
265272
}
266273

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

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

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

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

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

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

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

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

336+
/// Determine if there is an overlap between types.
321337
pub fn type_overlap(&self, t1: &MetaType<S>, t2: &MetaType<S>) -> bool {
322338
if (t1 as *const MetaType<S>) == (t2 as *const MetaType<S>) {
323339
return true;
@@ -334,6 +350,7 @@ impl<'a, S> SchemaType<'a, S> {
334350
}
335351
}
336352

353+
/// A list of possible typeees for a given type.
337354
pub fn possible_types(&self, t: &MetaType<S>) -> Vec<&MetaType<S>> {
338355
match *t {
339356
MetaType::Union(UnionMeta {
@@ -357,6 +374,7 @@ impl<'a, S> SchemaType<'a, S> {
357374
}
358375
}
359376

377+
/// If the abstract type is possible.
360378
pub fn is_possible_type(
361379
&self,
362380
abstract_type: &MetaType<S>,
@@ -367,6 +385,7 @@ impl<'a, S> SchemaType<'a, S> {
367385
.any(|t| (t as *const MetaType<S>) == (possible_type as *const MetaType<S>))
368386
}
369387

388+
/// If the type is a subtype of another type.
370389
pub fn is_subtype<'b>(&self, sub_type: &Type<'b>, super_type: &Type<'b>) -> bool {
371390
use crate::ast::Type::*;
372391

@@ -389,6 +408,7 @@ impl<'a, S> SchemaType<'a, S> {
389408
}
390409
}
391410

411+
/// If the type is a named subtype.
392412
pub fn is_named_subtype(&self, sub_type_name: &str, super_type_name: &str) -> bool {
393413
if sub_type_name == super_type_name {
394414
true

juniper/src/types/scalars.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ where
340340
///
341341
/// If you instantiate `RootNode` with this as the subscription,
342342
/// no subscriptions will be generated for the schema.
343+
#[derive(Default)]
343344
pub struct EmptySubscription<T> {
344345
phantom: PhantomData<T>,
345346
}

juniper/src/types/subscriptions.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,20 @@ where
364364
} else if let Err(e) = sub_result {
365365
sub_exec.push_error_at(e, start_pos.clone());
366366
}
367-
} else {
368-
if let Some(type_name) = meta_type.name() {
369-
let sub_result = instance
370-
.resolve_into_type_stream(info, type_name, &sub_exec)
371-
.await;
372-
373-
if let Ok(Value::Object(obj)) = sub_result {
374-
for (k, v) in obj {
375-
merge_key_into(&mut object, &k, v);
376-
}
377-
} else if let Err(e) = sub_result {
378-
sub_exec.push_error_at(e, start_pos.clone());
367+
} else if let Some(type_name) = meta_type.name() {
368+
let sub_result = instance
369+
.resolve_into_type_stream(info, type_name, &sub_exec)
370+
.await;
371+
372+
if let Ok(Value::Object(obj)) = sub_result {
373+
for (k, v) in obj {
374+
merge_key_into(&mut object, &k, v);
379375
}
380-
} else {
381-
return Value::Null;
376+
} else if let Err(e) = sub_result {
377+
sub_exec.push_error_at(e, start_pos.clone());
382378
}
379+
} else {
380+
return Value::Null;
383381
}
384382
}
385383
}

juniper/src/validation/rules/variables_in_allowed_position.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, S: Debug> VariableInAllowedPosition<'a, S> {
3737
fn collect_incorrect_usages(
3838
&self,
3939
from: &Scope<'a>,
40-
var_defs: &Vec<&'a (Spanning<&'a str>, VariableDefinition<S>)>,
40+
var_defs: &[&'a (Spanning<&'a str>, VariableDefinition<S>)],
4141
ctx: &mut ValidatorContext<'a, S>,
4242
visited: &mut HashSet<Scope<'a>>,
4343
) {

juniper_codegen/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,13 @@ pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenSt
389389
/// A proc macro for defining a GraphQL subscription.
390390
#[proc_macro_attribute]
391391
pub fn graphql_subscription(args: TokenStream, input: TokenStream) -> TokenStream {
392-
let gen = impl_object::build_subscription(args, input, false);
393-
gen.into()
392+
impl_object::build_subscription(args, input, false)
394393
}
395394

396395
#[doc(hidden)]
397396
#[proc_macro_attribute]
398397
pub fn graphql_subscription_internal(args: TokenStream, input: TokenStream) -> TokenStream {
399-
let gen = impl_object::build_subscription(args, input, true);
400-
gen.into()
398+
impl_object::build_subscription(args, input, true)
401399
}
402400

403401
#[proc_macro_attribute]

juniper_subscriptions/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![deny(warnings)]
1212
#![doc(html_root_url = "https://docs.rs/juniper_subscriptions/0.14.2")]
1313

14-
use std::{borrow::BorrowMut as _, iter::FromIterator, pin::Pin};
14+
use std::{iter::FromIterator, pin::Pin};
1515

1616
use futures::{task::Poll, Stream};
1717
use juniper::{
@@ -197,12 +197,11 @@ where
197197
// TODO: iterate over i and (ref field_name, ref val) once
198198
// [this RFC](https://github.com/rust-lang/rust/issues/68354)
199199
// is implemented
200-
for i in 0..obj_len {
200+
for ready in ready_vec.iter_mut().take(obj_len) {
201201
let (field_name, val) = match obj_iterator.next() {
202202
Some(v) => v,
203203
None => break,
204204
};
205-
let ready = ready_vec[i].borrow_mut();
206205

207206
if ready.is_some() {
208207
continue;

0 commit comments

Comments
 (0)