Skip to content

Commit 6f18858

Browse files
committed
Bootstrap compile-time check [skip ci]
1 parent c75b9c5 commit 6f18858

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

juniper/src/macros/reflect.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,20 @@ pub const fn can_be_subtype(ty: WrappedValue, subtype: WrappedValue) -> bool {
457457
}
458458
}
459459

460+
/// Extracts an [`Argument`] from the provided [`Arguments`] by its [`Name`].
461+
#[must_use]
462+
pub const fn extract_argument(args: Arguments, name: Name) -> Option<Argument> {
463+
let mut i = 0;
464+
while i < args.len() {
465+
let arg = args[i];
466+
if str_eq(arg.0, name) {
467+
return Some(arg);
468+
}
469+
i += 1;
470+
}
471+
None
472+
}
473+
460474
/// Checks whether the given `val` exists in the given `arr`.
461475
#[must_use]
462476
pub const fn str_exists_in_arr(val: &str, arr: &[&str]) -> bool {
@@ -863,6 +877,36 @@ macro_rules! assert_field_args {
863877
};
864878
}
865879

880+
#[macro_export]
881+
macro_rules! assert_field_arg_nullable {
882+
(
883+
$ty: ty,
884+
$scalar: ty,
885+
$field_name: expr,
886+
$arg_name: expr
887+
$(, $err_prefix: expr)? $(,)?
888+
) => {
889+
const {
890+
const TY_NAME: &::core::primitive::str =
891+
<$ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
892+
const FIELD_NAME: &::core::primitive::str = $field_name;
893+
const ARGS: $crate::macros::reflect::Arguments =
894+
<$ty as $crate::macros::reflect::FieldMeta<
895+
$scalar,
896+
{ $crate::checked_hash!(FIELD_NAME, $ty, $scalar, $err_prefix) },
897+
>>::ARGUMENTS;
898+
const ARG_NAME: &::core::primitive::str = $arg_name;
899+
const ARG: $crate::macros::reflect::Argument =
900+
$crate::macros::reflect::extract_argument(ARGS, ARG_NAME).unwrap(
901+
$crate::const_concat!(
902+
$err_prefix, "Field `", FIELD_NAME, "` has no argument `", ARG_NAME, "`",
903+
),
904+
);
905+
todo!()
906+
}
907+
};
908+
}
909+
866910
/// Concatenates `const` [`str`](prim@str)s in a `const` context.
867911
#[macro_export]
868912
macro_rules! const_concat {

juniper_codegen/src/common/field/arg.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,13 @@ impl OnMethod {
313313
/// [`marker::IsOutputType::mark`]: juniper::marker::IsOutputType::mark
314314
#[must_use]
315315
pub(crate) fn method_mark_tokens(&self, scalar: &scalar::Type) -> Option<TokenStream> {
316-
let ty = &self.as_regular()?.ty;
316+
let arg = self.as_regular()?;
317+
let ty = &arg.ty;
318+
319+
if arg.deprecated.is_some() && arg.default.is_none() {
320+
// TODO: Panic in compile time if not `Null`able.
321+
}
322+
317323
Some(quote_spanned! { ty.span() =>
318324
<#ty as ::juniper::marker::IsInputType<#scalar>>::mark();
319325
})

0 commit comments

Comments
 (0)