parent
fce45ece3f
commit
1af950401c
3 changed files with 88 additions and 14 deletions
src/macros
|
@ -64,10 +64,10 @@ macro_rules! graphql_input_object {
|
||||||
// Generate the struct declaration, including (Rust) meta attributes
|
// Generate the struct declaration, including (Rust) meta attributes
|
||||||
(
|
(
|
||||||
@generate_struct_fields,
|
@generate_struct_fields,
|
||||||
( $($meta:tt)* ), $name:tt,
|
( $($meta:tt)* ), ( $($pubmod:tt)* ), $name:tt,
|
||||||
( $($field_name:ident : $field_type:ty $(as $descr:tt)* $(,)* ),* )
|
( $($field_name:ident : $field_type:ty $(as $descr:tt)* $(,)* ),* )
|
||||||
) => {
|
) => {
|
||||||
$($meta)* struct $name {
|
$($meta)* $($pubmod)* struct $name {
|
||||||
$( $field_name: $field_type, )*
|
$( $field_name: $field_type, )*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -93,12 +93,26 @@ macro_rules! graphql_input_object {
|
||||||
// struct $name { ... }
|
// struct $name { ... }
|
||||||
(
|
(
|
||||||
@parse,
|
@parse,
|
||||||
( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $descr:tt ),
|
( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ),
|
||||||
$(#[$meta:meta])* struct $name:ident { $($fields:tt)* } $($rest:tt)*
|
$(#[$meta:meta])* struct $name:ident { $($fields:tt)* } $($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
graphql_input_object!(
|
graphql_input_object!(
|
||||||
@parse,
|
@parse,
|
||||||
( ( $(#[$meta])* ), $name, (stringify!($name)), ($($fields)*), $descr ),
|
( ( $(#[$meta])* ), ( ), $name, (stringify!($name)), ($($fields)*), $descr ),
|
||||||
|
$($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// #[...] pub struct $name { ... }
|
||||||
|
// pub struct $name { ... }
|
||||||
|
(
|
||||||
|
@parse,
|
||||||
|
( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ),
|
||||||
|
$(#[$meta:meta])* pub struct $name:ident { $($fields:tt)* } $($rest:tt)*
|
||||||
|
) => {
|
||||||
|
graphql_input_object!(
|
||||||
|
@parse,
|
||||||
|
( ( $(#[$meta])* ), ( pub ), $name, (stringify!($name)), ($($fields)*), $descr ),
|
||||||
$($rest)*
|
$($rest)*
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -107,12 +121,26 @@ macro_rules! graphql_input_object {
|
||||||
// struct $name as "GraphQLName" { ... }
|
// struct $name as "GraphQLName" { ... }
|
||||||
(
|
(
|
||||||
@parse,
|
@parse,
|
||||||
( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $descr:tt ),
|
( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ),
|
||||||
$(#[$meta:meta])* struct $name:ident as $outname:tt { $($fields:tt)* } $($rest:tt)*
|
$(#[$meta:meta])* struct $name:ident as $outname:tt { $($fields:tt)* } $($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
graphql_input_object!(
|
graphql_input_object!(
|
||||||
@parse,
|
@parse,
|
||||||
( ( $($meta)* ), $name, $outname, ($($fields)*), $descr ),
|
( ( $($meta)* ), ( ), $name, $outname, ($($fields)*), $descr ),
|
||||||
|
$($rest)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// #[...] pub struct $name as "GraphQLName" { ... }
|
||||||
|
// pub struct $name as "GraphQLName" { ... }
|
||||||
|
(
|
||||||
|
@parse,
|
||||||
|
( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ),
|
||||||
|
$(#[$meta:meta])* pub struct $name:ident as $outname:tt { $($fields:tt)* } $($rest:tt)*
|
||||||
|
) => {
|
||||||
|
graphql_input_object!(
|
||||||
|
@parse,
|
||||||
|
( ( $($meta)* ), ( pub ), $name, $outname, ($($fields)*), $descr ),
|
||||||
$($rest)*
|
$($rest)*
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -120,12 +148,12 @@ macro_rules! graphql_input_object {
|
||||||
// description: <description>
|
// description: <description>
|
||||||
(
|
(
|
||||||
@parse,
|
@parse,
|
||||||
( $meta:tt, $name:tt, $outname:tt, $fields:tt, $_ignore:tt ),
|
( $meta:tt, $pubmod:tt, $name:tt, $outname:tt, $fields:tt, $_ignore:tt ),
|
||||||
description: $descr:tt $($rest:tt)*
|
description: $descr:tt $($rest:tt)*
|
||||||
) => {
|
) => {
|
||||||
graphql_input_object!(
|
graphql_input_object!(
|
||||||
@parse,
|
@parse,
|
||||||
( $meta, $name, $outname, $fields, $descr ),
|
( $meta, $pubmod, $name, $outname, $fields, $descr ),
|
||||||
$($rest)*
|
$($rest)*
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -133,9 +161,9 @@ macro_rules! graphql_input_object {
|
||||||
// No more data to parse, generate the struct and impls
|
// No more data to parse, generate the struct and impls
|
||||||
(
|
(
|
||||||
@parse,
|
@parse,
|
||||||
( $meta:tt, $name:tt, $outname:tt, $fields:tt, $descr:tt ),
|
( $meta:tt, $pubmod:tt, $name:tt, $outname:tt, $fields:tt, $descr:tt ),
|
||||||
) => {
|
) => {
|
||||||
graphql_input_object!(@generate_struct_fields, $meta, $name, $fields);
|
graphql_input_object!(@generate_struct_fields, $meta, $pubmod, $name, $fields);
|
||||||
|
|
||||||
impl $crate::FromInputValue for $name {
|
impl $crate::FromInputValue for $name {
|
||||||
fn from(value: &$crate::InputValue) -> Option<$name> {
|
fn from(value: &$crate::InputValue) -> Option<$name> {
|
||||||
|
@ -164,20 +192,29 @@ macro_rules! graphql_input_object {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Entry point: parse calls starting with the struct declaration
|
// Entry point: parse calls starting with a struct declaration
|
||||||
( $(#[$meta:meta])* struct $($items:tt)* ) => {
|
( $(#[$meta:meta])* struct $($items:tt)* ) => {
|
||||||
graphql_input_object!(
|
graphql_input_object!(
|
||||||
@parse,
|
@parse,
|
||||||
( ( ), None, None, None, None ),
|
( ( ), ( ), None, None, None, None ),
|
||||||
$(#[$meta])* struct $($items)*
|
$(#[$meta])* struct $($items)*
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Entry point: parse calls starting with a public struct declaration
|
||||||
|
( $(#[$meta:meta])* pub struct $($items:tt)* ) => {
|
||||||
|
graphql_input_object!(
|
||||||
|
@parse,
|
||||||
|
( ( ), ( ), None, None, None, None ),
|
||||||
|
$(#[$meta])* pub struct $($items)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Entry point: parse calls starting with the description
|
// Entry point: parse calls starting with the description
|
||||||
( description: $($items:tt)* ) => {
|
( description: $($items:tt)* ) => {
|
||||||
graphql_input_object!(
|
graphql_input_object!(
|
||||||
@parse,
|
@parse,
|
||||||
( ( ), None, None, None, None ),
|
( ( ), ( ), None, None, None, None ),
|
||||||
description: $($items)*
|
description: $($items)*
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,6 +42,34 @@ graphql_input_object!(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
graphql_input_object!(
|
||||||
|
pub struct Public {
|
||||||
|
field_one: String,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
graphql_input_object!(
|
||||||
|
description: "Description for the input object"
|
||||||
|
|
||||||
|
pub struct PublicWithDescription {
|
||||||
|
field_one: String,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
graphql_input_object!(
|
||||||
|
description: "Description for the input object"
|
||||||
|
|
||||||
|
pub struct NamedPublicWithDescription as "APublicNamedInputObjectWithDescription" {
|
||||||
|
field_one: String,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
graphql_input_object!(
|
||||||
|
pub struct NamedPublic as "APublicNamedInputObject" {
|
||||||
|
field_one: String,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
graphql_input_object!(
|
graphql_input_object!(
|
||||||
struct FieldDescription {
|
struct FieldDescription {
|
||||||
field_one: String as "The first field",
|
field_one: String as "The first field",
|
||||||
|
@ -56,7 +84,11 @@ graphql_object!(Root: () |&self| {
|
||||||
a3: Derive,
|
a3: Derive,
|
||||||
a4: Named,
|
a4: Named,
|
||||||
a5: Description,
|
a5: Description,
|
||||||
a6: FieldDescription
|
a6: FieldDescription,
|
||||||
|
a7: Public,
|
||||||
|
a8: PublicWithDescription,
|
||||||
|
a9: NamedPublicWithDescription,
|
||||||
|
a10: NamedPublic,
|
||||||
) -> i64 {
|
) -> i64 {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,3 +6,8 @@ mod field;
|
||||||
mod object;
|
mod object;
|
||||||
mod interface;
|
mod interface;
|
||||||
mod union;
|
mod union;
|
||||||
|
|
||||||
|
|
||||||
|
// This asserts that the input objects defined public actually became public
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use self::input_object::{NamedPublic, NamedPublicWithDescription};
|
||||||
|
|
Loading…
Add table
Reference in a new issue