Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd62781

Browse files
authored
feat: add @requiresScopes support (#1695)
1 parent3001a02 commitbd62781

32 files changed

+386
-23
lines changed

‎derive/src/args.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ pub struct SimpleObjectField {
235235
#[darling(default, multiple, rename ="directive")]
236236
pubdirectives:Vec<Expr>,
237237
pubcomplexity:Option<Expr>,
238+
#[darling(default, multiple)]
239+
pubrequires_scopes:Vec<String>,
238240
}
239241

240242
#[derive(FromDeriveInput)]
@@ -286,6 +288,8 @@ pub struct SimpleObject {
286288
pubguard:Option<Expr>,
287289
#[darling(default, multiple, rename ="directive")]
288290
pubdirectives:Vec<Expr>,
291+
#[darling(default, multiple)]
292+
pubrequires_scopes:Vec<String>,
289293
}
290294

291295
#[derive(FromMeta,Default)]
@@ -335,6 +339,8 @@ pub struct Object {
335339
pubguard:Option<Expr>,
336340
#[darling(default, multiple, rename ="directive")]
337341
pubdirectives:Vec<Expr>,
342+
#[darling(default, multiple)]
343+
pubrequires_scopes:Vec<String>,
338344
}
339345

340346
#[derive(FromMeta,Default)]
@@ -361,6 +367,8 @@ pub struct ObjectField {
361367
pubflatten:bool,
362368
#[darling(default, multiple, rename ="directive")]
363369
pubdirectives:Vec<Expr>,
370+
#[darling(default, multiple)]
371+
pubrequires_scopes:Vec<String>,
364372
}
365373

366374
#[derive(FromMeta,Default,Clone)]
@@ -402,6 +410,8 @@ pub struct Enum {
402410
pubtags:Vec<String>,
403411
#[darling(default, multiple, rename ="directive")]
404412
pubdirectives:Vec<Expr>,
413+
#[darling(default, multiple)]
414+
pubrequires_scopes:Vec<String>,
405415
}
406416

407417
#[derive(FromVariant)]
@@ -656,6 +666,8 @@ pub struct InterfaceField {
656666
puboverride_from:Option<String>,
657667
#[darling(default, multiple, rename ="directive")]
658668
pubdirectives:Vec<Expr>,
669+
#[darling(default, multiple)]
670+
pubrequires_scopes:Vec<String>,
659671
}
660672

661673
#[derive(FromVariant)]
@@ -697,6 +709,8 @@ pub struct Interface {
697709
// for OneofObject
698710
#[darling(default)]
699711
pubinput_name:Option<String>,
712+
#[darling(default, multiple)]
713+
pubrequires_scopes:Vec<String>,
700714
}
701715

702716
#[derive(FromMeta,Default)]
@@ -712,6 +726,8 @@ pub struct Scalar {
712726
#[darling(multiple, rename ="tag")]
713727
pubtags:Vec<String>,
714728
pubspecified_by_url:Option<String>,
729+
#[darling(default, multiple)]
730+
pubrequires_scopes:Vec<String>,
715731
}
716732

717733
#[derive(FromMeta,Default)]
@@ -982,6 +998,8 @@ pub struct ComplexObjectField {
982998
pubflatten:bool,
983999
#[darling(default, multiple, rename ="directive")]
9841000
pubdirectives:Vec<Expr>,
1001+
#[darling(default, multiple)]
1002+
pubrequires_scopes:Vec<String>,
9851003
}
9861004

9871005
#[derive(FromMeta,Default)]

‎derive/src/complex_object.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ pub fn generate(
191191
.iter()
192192
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
193193
.collect::<Vec<_>>();
194+
let requires_scopes = method_args
195+
.requires_scopes
196+
.iter()
197+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
198+
.collect::<Vec<_>>();
194199
let requires =match&method_args.requires{
195200
Some(requires) =>{
196201
quote!{::std::option::Option::Some(::std::string::ToString::to_string(#requires))}
@@ -401,6 +406,7 @@ pub fn generate(
401406
visible: #visible,
402407
compute_complexity: #complexity,
403408
directive_invocations:::std::vec![ #(#directives),*],
409+
requires_scopes:::std::vec![ #(#requires_scopes),*],
404410
}));
405411
});
406412

‎derive/src/enum.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub fn generate(enum_args: &args::Enum) -> GeneratorResult<TokenStream> {
3636
.iter()
3737
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
3838
.collect::<Vec<_>>();
39+
let requires_scopes = enum_args
40+
.requires_scopes
41+
.iter()
42+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
43+
.collect::<Vec<_>>();
3944
let directives =gen_directive_calls(&enum_args.directives,TypeDirectiveLocation::Enum);
4045
let desc =get_rustdoc(&enum_args.attrs)?
4146
.map(|s|quote!{::std::option::Option::Some(::std::string::ToString::to_string(#s))})
@@ -187,7 +192,8 @@ pub fn generate(enum_args: &args::Enum) -> GeneratorResult<TokenStream> {
187192
inaccessible: #inaccessible,
188193
tags:::std::vec![ #(#tags),*],
189194
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
190-
directive_invocations:::std::vec![ #(#directives),*]
195+
directive_invocations:::std::vec![ #(#directives),*],
196+
requires_scopes:::std::vec![ #(#requires_scopes),*],
191197
}
192198
})
193199
}

‎derive/src/interface.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
4242
.iter()
4343
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
4444
.collect::<Vec<_>>();
45+
let requires_scopes = interface_args
46+
.requires_scopes
47+
.iter()
48+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
49+
.collect::<Vec<_>>();
4550
let directives =
4651
gen_directive_calls(&interface_args.directives,TypeDirectiveLocation::Interface);
4752
let gql_typename =if !interface_args.name_type{
@@ -160,6 +165,7 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
160165
tags,
161166
override_from,
162167
directives,
168+
requires_scopes,
163169
}in&interface_args.fields
164170
{
165171
let(name, method_name) =ifletSome(method) = method{
@@ -307,6 +313,10 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
307313
.iter()
308314
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
309315
.collect::<Vec<_>>();
316+
let requires_scopes = requires_scopes
317+
.iter()
318+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
319+
.collect::<Vec<_>>();
310320
let directives =gen_directive_calls(directives,TypeDirectiveLocation::FieldDefinition);
311321

312322
schema_fields.push(quote!{
@@ -331,6 +341,7 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
331341
visible: #visible,
332342
compute_complexity:::std::option::Option::None,
333343
directive_invocations:::std::vec![ #(#directives),*],
344+
requires_scopes:::std::vec![ #(#requires_scopes),*],
334345
});
335346
});
336347

@@ -417,7 +428,8 @@ pub fn generate(interface_args: &args::Interface) -> GeneratorResult<TokenStream
417428
inaccessible: #inaccessible,
418429
tags:::std::vec![ #(#tags),*],
419430
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
420-
directive_invocations:::std::vec![ #(#directives),*]
431+
directive_invocations:::std::vec![ #(#directives),*],
432+
requires_scopes:::std::vec![ #(#requires_scopes),*],
421433
}
422434
})
423435
}

‎derive/src/merged_object.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub fn generate(object_args: &args::MergedObject) -> GeneratorResult<TokenStream
134134
is_subscription:false,
135135
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
136136
directive_invocations:::std::vec![ #(#directives),*],
137+
requires_scopes:::std::vec![],
137138
}
138139
})
139140
}

‎derive/src/merged_subscription.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub fn generate(object_args: &args::MergedSubscription) -> GeneratorResult<Token
8888
is_subscription:true,
8989
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
9090
directive_invocations:::std::default::Default::default(),
91+
requires_scopes:::std::default::Default::default(),
9192
}
9293
})
9394
}

‎derive/src/newtype.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub fn generate(newtype_args: &args::NewType) -> GeneratorResult<TokenStream> {
6262
tags:::std::vec![ #(#tags),*],
6363
specified_by_url: #specified_by_url,
6464
directive_invocations:::std::vec::Vec::new(),
65+
requires_scopes:::std::vec::Vec::new(),
6566
})
6667
}
6768
}else{

‎derive/src/object.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ pub fn generate(
3838
.iter()
3939
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
4040
.collect::<Vec<_>>();
41+
let requires_scopes = object_args
42+
.requires_scopes
43+
.iter()
44+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
45+
.collect::<Vec<_>>();
4146
let directives =gen_directive_calls(&object_args.directives,TypeDirectiveLocation::Object);
4247
let gql_typename =if !object_args.name_type{
4348
object_args
@@ -340,6 +345,11 @@ pub fn generate(
340345
.iter()
341346
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
342347
.collect::<Vec<_>>();
348+
let requires_scopes = method_args
349+
.requires_scopes
350+
.iter()
351+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
352+
.collect::<Vec<_>>();
343353

344354
unresolvable_key.push_str(&field_name);
345355
unresolvable_key.push(' ');
@@ -539,7 +549,8 @@ pub fn generate(
539549
override_from: #override_from,
540550
visible: #visible,
541551
compute_complexity: #complexity,
542-
directive_invocations:::std::vec![ #(#directives),*]
552+
directive_invocations:::std::vec![ #(#directives),*],
553+
requires_scopes:::std::vec![ #(#requires_scopes),*],
543554
});
544555
});
545556

@@ -703,7 +714,8 @@ pub fn generate(
703714
visible: #visible,
704715
is_subscription:false,
705716
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
706-
directive_invocations:::std::vec![ #(#directives),*]
717+
directive_invocations:::std::vec![ #(#directives),*],
718+
requires_scopes:::std::vec![ #(#requires_scopes),*],
707719
});
708720
#(#create_entity_types)*
709721
#(#add_keys)*
@@ -757,6 +769,7 @@ pub fn generate(
757769
is_subscription:false,
758770
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
759771
directive_invocations:::std::vec![ #(#directives),*],
772+
requires_scopes:::std::vec![],
760773
});
761774
#(#create_entity_types)*
762775
#(#add_keys)*

‎derive/src/scalar.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ pub fn generate(
4545
.iter()
4646
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
4747
.collect::<Vec<_>>();
48+
let requires_scopes = scalar_args
49+
.requires_scopes
50+
.iter()
51+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
52+
.collect::<Vec<_>>();
4853
let specified_by_url =match&scalar_args.specified_by_url{
4954
Some(specified_by_url) =>{
5055
quote!{::std::option::Option::Some(::std::string::ToString::to_string(#specified_by_url))}
@@ -73,6 +78,7 @@ pub fn generate(
7378
tags:::std::vec![ #(#tags),*],
7479
specified_by_url: #specified_by_url,
7580
directive_invocations:::std::vec::Vec::new(),
81+
requires_scopes:::std::vec![ #(#requires_scopes),*],
7682
})
7783
}
7884

@@ -105,7 +111,8 @@ pub fn generate(
105111
inaccessible: #inaccessible,
106112
tags:::std::vec![ #(#tags),*],
107113
specified_by_url: #specified_by_url,
108-
directive_invocations:::std::vec::Vec::new()
114+
directive_invocations:::std::vec::Vec::new(),
115+
requires_scopes:::std::vec![ #(#requires_scopes),*],
109116
})
110117
}
111118

‎derive/src/simple_object.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
4343
.iter()
4444
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
4545
.collect::<Vec<_>>();
46+
let requires_scopes = object_args
47+
.requires_scopes
48+
.iter()
49+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
50+
.collect::<Vec<_>>();
4651
let object_directives =
4752
gen_directive_calls(&object_args.directives,TypeDirectiveLocation::Object);
4853
let gql_typename =if !object_args.name_type{
@@ -149,6 +154,11 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
149154
.iter()
150155
.map(|tag|quote!(::std::string::ToString::to_string(#tag)))
151156
.collect::<Vec<_>>();
157+
let requires_scopes = field
158+
.requires_scopes
159+
.iter()
160+
.map(|scopes|quote!(::std::string::ToString::to_string(#scopes)))
161+
.collect::<Vec<_>>();
152162
let override_from =match&field.override_from{
153163
Some(from) =>{
154164
quote!{::std::option::Option::Some(::std::string::ToString::to_string(#from))}
@@ -189,11 +199,11 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
189199
field.cache_control.max_ageasi32
190200
};
191201
quote!{
192-
#crate_name::CacheControl{
193-
public: #public,
194-
max_age: #max_age,
202+
#crate_name::CacheControl{
203+
public: #public,
204+
max_age: #max_age,
205+
}
195206
}
196-
}
197207
};
198208

199209
let visible =visible_fn(&field.visible);
@@ -230,6 +240,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
230240
visible: #visible,
231241
compute_complexity: #complexity,
232242
directive_invocations:::std::vec![ #(#directives),*],
243+
requires_scopes:::std::vec![ #(#requires_scopes),*],
233244
});
234245
});
235246
}else{
@@ -430,6 +441,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
430441
is_subscription:false,
431442
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
432443
directive_invocations:::std::vec![ #(#object_directives),*],
444+
requires_scopes:::std::vec![ #(#requires_scopes),*],
433445
})
434446
}
435447

@@ -494,6 +506,7 @@ pub fn generate(object_args: &args::SimpleObject) -> GeneratorResult<TokenStream
494506
is_subscription:false,
495507
rust_typename:::std::option::Option::Some(::std::any::type_name::<Self>()),
496508
directive_invocations:::std::vec![ #(#object_directives),*],
509+
requires_scopes:::std::vec![ #(#requires_scopes),*],
497510
})
498511
}
499512

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp