Skip to content

Commit 0d85e1a

Browse files
committed
Resculpt ast::Type, vol.4 (finally works!)
1 parent d9d8f3a commit 0d85e1a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

juniper/src/ast.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ where
7272
}
7373

7474
impl<'a> BorrowedType<'a> {
75+
pub(crate) fn non_null(name: &'a str) -> Self {
76+
Self {
77+
name,
78+
modifiers: &[TypeModifier::NonNull],
79+
}
80+
}
81+
7582
pub(crate) fn inner_borrowed(&self) -> BorrowedType<'a> {
7683
let modifiers = self.modifiers.as_ref();
7784
match modifiers.len() {

juniper/src/validation/visitor.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
validation::{ValidatorContext, Visitor, multi_visitor::MultiVisitorCons},
1212
value::ScalarValue,
1313
};
14+
use crate::ast::BorrowedType;
1415

1516
#[doc(hidden)]
1617
pub fn visit<'a, A, B, S>(
@@ -40,15 +41,17 @@ where
4041
..
4142
},
4243
..
43-
}) => Some(Type::named(*name).wrap_non_null()),
44+
}) => Some(BorrowedType::non_null(name)),
4445
Definition::Operation(Spanning {
4546
item:
4647
Operation {
4748
operation_type: OperationType::Query,
4849
..
4950
},
5051
..
51-
}) => Some(ctx.schema.concrete_query_type().as_type()),
52+
}) => Some(BorrowedType::non_null(
53+
ctx.schema.concrete_query_type().name().unwrap(),
54+
)),
5255
Definition::Operation(Spanning {
5356
item:
5457
Operation {
@@ -59,7 +62,7 @@ where
5962
}) => ctx
6063
.schema
6164
.concrete_mutation_type()
62-
.map(|t| t.as_type()),
65+
.map(|t| BorrowedType::non_null(t.name().unwrap())),
6366
Definition::Operation(Spanning {
6467
item:
6568
Operation {
@@ -70,10 +73,10 @@ where
7073
}) => ctx
7174
.schema
7275
.concrete_subscription_type()
73-
.map(|t| t.as_type()),
76+
.map(|t| BorrowedType::non_null(t.name().unwrap())),
7477
};
7578

76-
ctx.with_pushed_type(def_type.as_ref(), |ctx| {
79+
ctx.with_pushed_type(def_type, |ctx| {
7780
enter_definition(v, ctx, def);
7881
visit_definition(v, ctx, def);
7982
exit_definition(v, ctx, def);
@@ -306,7 +309,7 @@ fn visit_inline_fragment<'a, S, V>(
306309
item: type_name, ..
307310
}) = fragment.item.type_condition
308311
{
309-
ctx.with_pushed_type(Some(&Type::<&str>::named(type_name).wrap_non_null()), visit_fn);
312+
ctx.with_pushed_type(Some(BorrowedType::non_null(type_name)), visit_fn);
310313
} else {
311314
visit_fn(ctx);
312315
}

0 commit comments

Comments
 (0)