2020-09-28 09:44:00 +00:00
|
|
|
use darling::ast::{Data, Fields};
|
|
|
|
use darling::util::Ignored;
|
|
|
|
use darling::{FromDeriveInput, FromField, FromMeta, FromVariant};
|
2020-10-14 09:08:57 +00:00
|
|
|
use inflector::Inflector;
|
2021-01-14 03:27:15 +00:00
|
|
|
use syn::{
|
|
|
|
Attribute, Generics, Ident, Lit, LitBool, LitStr, Meta, NestedMeta, Path, Type, Visibility,
|
|
|
|
};
|
2020-03-22 08:45:59 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta)]
|
|
|
|
#[darling(default)]
|
2020-03-22 08:45:59 +00:00
|
|
|
pub struct CacheControl {
|
2020-09-28 09:44:00 +00:00
|
|
|
public: bool,
|
|
|
|
private: bool,
|
2020-03-22 08:45:59 +00:00
|
|
|
pub max_age: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for CacheControl {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
public: true,
|
2020-09-28 09:44:00 +00:00
|
|
|
private: false,
|
2020-03-22 08:45:59 +00:00
|
|
|
max_age: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CacheControl {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub fn is_public(&self) -> bool {
|
|
|
|
!self.private && self.public
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum DefaultValue {
|
|
|
|
Default,
|
|
|
|
Value(Lit),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromMeta for DefaultValue {
|
|
|
|
fn from_word() -> darling::Result<Self> {
|
|
|
|
Ok(DefaultValue::Default)
|
|
|
|
}
|
2020-03-22 08:45:59 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
fn from_value(value: &Lit) -> darling::Result<Self> {
|
|
|
|
Ok(DefaultValue::Value(value.clone()))
|
2020-03-22 08:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-12-11 08:03:28 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Visible {
|
|
|
|
None,
|
|
|
|
HiddenAlways,
|
|
|
|
FnName(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromMeta for Visible {
|
|
|
|
fn from_value(value: &Lit) -> darling::Result<Self> {
|
|
|
|
match value {
|
|
|
|
Lit::Bool(LitBool { value: true, .. }) => Ok(Visible::None),
|
|
|
|
Lit::Bool(LitBool { value: false, .. }) => Ok(Visible::HiddenAlways),
|
|
|
|
Lit::Str(str) => Ok(Visible::FnName(str.value())),
|
|
|
|
_ => Err(darling::Error::unexpected_lit_type(value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 04:41:59 +00:00
|
|
|
pub struct PathList(pub Vec<Path>);
|
|
|
|
|
|
|
|
impl FromMeta for PathList {
|
|
|
|
fn from_list(items: &[NestedMeta]) -> darling::Result<Self> {
|
|
|
|
let mut res = Vec::new();
|
|
|
|
for item in items {
|
|
|
|
if let NestedMeta::Meta(Meta::Path(p)) = item {
|
|
|
|
res.push(p.clone());
|
|
|
|
} else {
|
|
|
|
return Err(darling::Error::custom("Invalid path list"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(PathList(res))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromMeta)]
|
|
|
|
pub struct ConcreteType {
|
|
|
|
pub name: String,
|
|
|
|
pub params: PathList,
|
|
|
|
}
|
|
|
|
|
2021-02-27 03:59:58 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Deprecation {
|
|
|
|
NoDeprecated,
|
|
|
|
Deprecated { reason: Option<String> },
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Deprecation {
|
|
|
|
fn default() -> Self {
|
|
|
|
Deprecation::NoDeprecated
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromMeta for Deprecation {
|
|
|
|
fn from_word() -> darling::Result<Self> {
|
|
|
|
Ok(Deprecation::Deprecated { reason: None })
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_value(value: &Lit) -> darling::Result<Self> {
|
|
|
|
match value {
|
|
|
|
Lit::Bool(LitBool { value: true, .. }) => Ok(Deprecation::Deprecated { reason: None }),
|
|
|
|
Lit::Bool(LitBool { value: false, .. }) => Ok(Deprecation::NoDeprecated),
|
|
|
|
Lit::Str(str) => Ok(Deprecation::Deprecated {
|
|
|
|
reason: Some(str.value()),
|
|
|
|
}),
|
|
|
|
_ => Err(darling::Error::unexpected_lit_type(value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromField)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct SimpleObjectField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
pub vis: Visibility,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub skip: bool,
|
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2021-02-27 03:59:58 +00:00
|
|
|
pub deprecation: Deprecation,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub owned: bool,
|
|
|
|
#[darling(default)]
|
2020-03-22 08:45:59 +00:00
|
|
|
pub cache_control: CacheControl,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub external: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub provides: Option<String>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub requires: Option<String>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub guard: Option<Meta>,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct SimpleObject {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, SimpleObjectField>,
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
2020-10-20 03:49:31 +00:00
|
|
|
pub dummy: bool,
|
|
|
|
#[darling(default)]
|
2020-09-28 09:44:00 +00:00
|
|
|
pub name: Option<String>,
|
|
|
|
#[darling(default)]
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub rename_args: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
2020-09-28 09:44:00 +00:00
|
|
|
pub cache_control: CacheControl,
|
|
|
|
#[darling(default)]
|
|
|
|
pub extends: bool,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2021-01-14 04:41:59 +00:00
|
|
|
#[darling(default, multiple, rename = "concrete")]
|
|
|
|
pub concretes: Vec<ConcreteType>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub struct Argument {
|
2020-03-05 06:23:55 +00:00
|
|
|
pub name: Option<String>,
|
2020-03-01 10:54:34 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
pub default_with: Option<LitStr>,
|
|
|
|
pub validator: Option<Meta>,
|
2020-06-19 04:37:52 +00:00
|
|
|
pub key: bool, // for entity
|
2020-12-11 08:03:28 +00:00
|
|
|
pub visible: Option<Visible>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct Object {
|
|
|
|
pub internal: bool,
|
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
pub rename_args: Option<RenameRule>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub cache_control: CacheControl,
|
|
|
|
pub extends: bool,
|
2020-10-26 13:34:05 +00:00
|
|
|
pub use_type_description: bool,
|
2020-12-11 08:03:28 +00:00
|
|
|
pub visible: Option<Visible>,
|
2020-03-05 06:23:55 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 06:59:37 +00:00
|
|
|
pub enum ComplexityType {
|
|
|
|
Const(usize),
|
|
|
|
Fn(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromMeta for ComplexityType {
|
|
|
|
fn from_value(value: &Lit) -> darling::Result<Self> {
|
|
|
|
match value {
|
|
|
|
Lit::Int(n) => {
|
|
|
|
let n = n.base10_parse::<i32>().unwrap();
|
|
|
|
if n < 0 {
|
|
|
|
return Err(darling::Error::custom(
|
|
|
|
"The complexity must be greater than or equal to 0.",
|
|
|
|
));
|
|
|
|
}
|
|
|
|
Ok(ComplexityType::Const(n as usize))
|
|
|
|
}
|
|
|
|
Lit::Str(s) => Ok(ComplexityType::Fn(s.value())),
|
|
|
|
_ => Err(darling::Error::unexpected_lit_type(value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct ObjectField {
|
|
|
|
pub skip: bool,
|
|
|
|
pub entity: bool,
|
2020-03-05 06:23:55 +00:00
|
|
|
pub name: Option<String>,
|
2021-02-27 03:59:58 +00:00
|
|
|
pub deprecation: Deprecation,
|
2020-03-22 08:45:59 +00:00
|
|
|
pub cache_control: CacheControl,
|
2020-04-09 14:03:09 +00:00
|
|
|
pub external: bool,
|
|
|
|
pub provides: Option<String>,
|
|
|
|
pub requires: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub guard: Option<Meta>,
|
2020-12-11 08:03:28 +00:00
|
|
|
pub visible: Option<Visible>,
|
2020-12-18 06:59:37 +00:00
|
|
|
pub complexity: Option<ComplexityType>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub struct Enum {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<EnumItem, Ignored>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-02 00:24:49 +00:00
|
|
|
pub internal: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_items: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
2020-09-27 08:05:25 +00:00
|
|
|
pub remote: Option<String>,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromVariant)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub struct EnumItem {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub fields: Fields<Ignored>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2021-02-27 03:59:58 +00:00
|
|
|
pub deprecation: Deprecation,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct Union {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<UnionItem, Ignored>,
|
2020-05-10 04:41:05 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub name: Option<String>,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromVariant)]
|
|
|
|
#[darling(attributes(graphql))]
|
2020-09-28 03:13:46 +00:00
|
|
|
pub struct UnionItem {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub fields: Fields<syn::Type>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-09-28 03:13:46 +00:00
|
|
|
pub flatten: bool,
|
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromField)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct InputObjectField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
pub vis: Visibility,
|
|
|
|
pub attrs: Vec<Attribute>,
|
2020-09-28 03:13:46 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub default_with: Option<LitStr>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub validator: Option<Meta>,
|
|
|
|
#[darling(default)]
|
2020-09-03 12:00:33 +00:00
|
|
|
pub flatten: bool,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
2020-12-15 12:29:59 +00:00
|
|
|
pub skip: bool,
|
|
|
|
#[darling(default)]
|
2020-12-11 08:03:28 +00:00
|
|
|
pub visible: Option<Visible>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-03 03:48:00 +00:00
|
|
|
pub struct InputObject {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, InputObjectField>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-03 03:48:00 +00:00
|
|
|
pub internal: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-03 03:48:00 +00:00
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub rename_fields: Option<RenameRule>,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2021-01-14 03:27:15 +00:00
|
|
|
#[darling(default, multiple, rename = "concrete")]
|
2021-01-14 04:41:59 +00:00
|
|
|
pub concretes: Vec<ConcreteType>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub struct InterfaceFieldArgument {
|
|
|
|
pub name: String,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(rename = "type")]
|
|
|
|
pub ty: LitStr,
|
|
|
|
#[darling(default)]
|
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub default_with: Option<LitStr>,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub struct InterfaceField {
|
|
|
|
pub name: String,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(rename = "type")]
|
|
|
|
pub ty: LitStr,
|
|
|
|
#[darling(default)]
|
2020-05-27 02:25:23 +00:00
|
|
|
pub method: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default, multiple, rename = "arg")]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub args: Vec<InterfaceFieldArgument>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2021-02-27 03:59:58 +00:00
|
|
|
pub deprecation: Deprecation,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub external: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub provides: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub requires: Option<String>,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromVariant)]
|
|
|
|
pub struct InterfaceMember {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub fields: Fields<syn::Type>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub struct Interface {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<InterfaceMember, Ignored>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub internal: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub rename_args: Option<RenameRule>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default, multiple, rename = "field")]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub fields: Vec<InterfaceField>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub extends: bool,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct Scalar {
|
|
|
|
pub internal: bool,
|
|
|
|
pub name: Option<String>,
|
2020-10-26 13:34:05 +00:00
|
|
|
pub use_type_description: bool,
|
2020-12-11 08:03:28 +00:00
|
|
|
pub visible: Option<Visible>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
2020-04-17 03:06:33 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct Subscription {
|
2020-04-27 09:58:10 +00:00
|
|
|
pub internal: bool,
|
2020-05-19 05:27:01 +00:00
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
pub rename_args: Option<RenameRule>,
|
2020-10-26 13:34:05 +00:00
|
|
|
pub use_type_description: bool,
|
2021-03-09 07:12:14 +00:00
|
|
|
pub extends: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct SubscriptionFieldArgument {
|
|
|
|
pub name: Option<String>,
|
2020-05-19 05:27:01 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
pub default_with: Option<LitStr>,
|
|
|
|
pub validator: Option<Meta>,
|
2020-12-11 08:03:28 +00:00
|
|
|
pub visible: Option<Visible>,
|
2020-04-27 09:58:10 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct SubscriptionField {
|
|
|
|
pub skip: bool,
|
|
|
|
pub name: Option<String>,
|
2021-02-27 03:59:58 +00:00
|
|
|
pub deprecation: Deprecation,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub guard: Option<Meta>,
|
2020-12-11 08:03:28 +00:00
|
|
|
pub visible: Option<Visible>,
|
2020-12-19 10:39:33 +00:00
|
|
|
pub complexity: Option<ComplexityType>,
|
2020-09-28 09:44:00 +00:00
|
|
|
}
|
2020-04-27 09:58:10 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromField)]
|
|
|
|
pub struct MergedObjectField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
}
|
2020-05-01 23:57:34 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct MergedObject {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, MergedObjectField>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub name: Option<String>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub cache_control: CacheControl,
|
|
|
|
#[darling(default)]
|
|
|
|
pub extends: bool,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2020-09-28 09:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromField)]
|
|
|
|
pub struct MergedSubscriptionField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct MergedSubscription {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, MergedSubscriptionField>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub name: Option<String>,
|
2020-12-11 08:03:28 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub visible: Option<Visible>,
|
2021-03-09 07:12:14 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub extends: bool,
|
2020-05-01 23:57:34 +00:00
|
|
|
}
|
2020-10-14 09:08:57 +00:00
|
|
|
|
2020-10-16 02:45:27 +00:00
|
|
|
#[derive(Debug, Copy, Clone, FromMeta)]
|
2020-10-14 09:08:57 +00:00
|
|
|
pub enum RenameRule {
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "lowercase")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Lower,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "UPPERCASE")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Upper,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "PascalCase")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Pascal,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "camelCase")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Camel,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "snake_case")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Snake,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "SCREAMING_SNAKE_CASE")]
|
2020-10-14 09:08:57 +00:00
|
|
|
ScreamingSnake,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenameRule {
|
|
|
|
fn rename(&self, name: impl AsRef<str>) -> String {
|
|
|
|
match self {
|
|
|
|
Self::Lower => name.as_ref().to_lowercase(),
|
|
|
|
Self::Upper => name.as_ref().to_uppercase(),
|
|
|
|
Self::Pascal => name.as_ref().to_pascal_case(),
|
|
|
|
Self::Camel => name.as_ref().to_camel_case(),
|
|
|
|
Self::Snake => name.as_ref().to_snake_case(),
|
|
|
|
Self::ScreamingSnake => name.as_ref().to_screaming_snake_case(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub enum RenameTarget {
|
|
|
|
Type,
|
|
|
|
EnumItem,
|
|
|
|
Field,
|
|
|
|
Argument,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenameTarget {
|
|
|
|
fn rule(&self) -> RenameRule {
|
|
|
|
match self {
|
|
|
|
RenameTarget::Type => RenameRule::Pascal,
|
|
|
|
RenameTarget::EnumItem => RenameRule::ScreamingSnake,
|
|
|
|
RenameTarget::Field => RenameRule::Camel,
|
|
|
|
RenameTarget::Argument => RenameRule::Camel,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn rename(&self, name: impl AsRef<str>) -> String {
|
|
|
|
self.rule().rename(name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait RenameRuleExt {
|
|
|
|
fn rename(&self, name: impl AsRef<str>, target: RenameTarget) -> String;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenameRuleExt for Option<RenameRule> {
|
|
|
|
fn rename(&self, name: impl AsRef<str>, target: RenameTarget) -> String {
|
|
|
|
self.unwrap_or(target.rule()).rename(name)
|
|
|
|
}
|
|
|
|
}
|
2020-10-26 13:34:05 +00:00
|
|
|
|
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(forward_attrs(doc))]
|
|
|
|
pub struct Description {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
}
|
2021-01-15 02:29:03 +00:00
|
|
|
|
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
pub struct NewType {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub data: Data<Ignored, syn::Type>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
}
|