Skip to content

Commit c8409e1

Browse files
committed
Remove ref attribute for SimpleObject fields, and add owned attribute.
1 parent 6172887 commit c8409e1

File tree

9 files changed

+16
-14
lines changed

9 files changed

+16
-14
lines changed

async-graphql-derive/src/args.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub struct Field {
202202
pub external: bool,
203203
pub provides: Option<String>,
204204
pub requires: Option<String>,
205-
pub is_ref: bool,
205+
pub owned: bool,
206206
pub guard: Option<TokenStream>,
207207
pub post_guard: Option<TokenStream>,
208208
pub features: Vec<String>,
@@ -218,7 +218,7 @@ impl Field {
218218
let mut provides = None;
219219
let mut requires = None;
220220
let mut features = Vec::new();
221-
let mut is_ref = false;
221+
let mut owned = false;
222222
let mut guard = None;
223223
let mut post_guard = None;
224224

@@ -235,8 +235,14 @@ impl Field {
235235
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("external") => {
236236
external = true;
237237
}
238+
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("owned") => {
239+
owned = true;
240+
}
238241
NestedMeta::Meta(Meta::Path(p)) if p.is_ident("ref") => {
239-
is_ref = true;
242+
return Err(Error::new_spanned(
243+
&p,
244+
"Attribute `ref` is no longer supported. By default, all fields resolver return borrowed value. If you want to return ownership value, use `owned` attribute.",
245+
));
240246
}
241247
NestedMeta::Meta(Meta::NameValue(nv)) => {
242248
if nv.path.is_ident("name") {
@@ -325,7 +331,7 @@ impl Field {
325331
external,
326332
provides,
327333
requires,
328-
is_ref,
334+
owned,
329335
guard,
330336
post_guard,
331337
features,

async-graphql-derive/src/simple_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn generate(object_args: &args::Object, input: &DeriveInput) -> Result<Token
9999
.map(|guard| quote! { #guard.check(ctx, &res).await.map_err(|err| err.into_error_with_path(ctx.position(), ctx.path_node.as_ref().unwrap().to_json()))?; });
100100

101101
let features = &field.features;
102-
getters.push(if field.is_ref {
102+
getters.push(if !field.owned {
103103
let block = feature_block(
104104
&crate_name,
105105
&features,

src/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,6 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
609609
/// struct MyObj {
610610
/// a: i32,
611611
/// b: i32,
612-
/// #[field(ref)]
613612
/// detail: Detail,
614613
/// }
615614
///

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ pub use async_graphql_derive::Object;
310310
/// | name | Field name | string | Y |
311311
/// | desc | Field description | string | Y |
312312
/// | deprecation | Field deprecation reason | string | Y |
313+
/// | owned | Field resolver return a ownedship value | bool | Y |
313314
/// | cache_control | Field cache control | [`CacheControl`](struct.CacheControl.html) | Y |
314315
/// | external | Mark a field as owned by another service. This allows service A to use fields from service B while also knowing at runtime the types of that field. | bool | Y |
315316
/// | provides | Annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the gateway. | string | Y |
@@ -398,7 +399,6 @@ pub use async_graphql_derive::GQLSimpleObject;
398399
/// | name | Item name | string | Y |
399400
/// | desc | Item description | string | Y |
400401
/// | deprecation | Item deprecation reason | string | Y |
401-
/// | ref | The resolver function returns a borrowing value | bool | Y |
402402
///
403403
/// # Examples
404404
///

src/look_ahead.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ mod tests {
7272
struct MyObj {
7373
a: i32,
7474
b: i32,
75-
#[field(ref)]
7675
detail: Detail,
7776
}
7877

tests/interface.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub async fn test_interface_simple_object() {
88
title: String,
99
}
1010

11-
#[async_graphql::Interface(field(name = "id", type = "i32"))]
11+
#[async_graphql::Interface(field(name = "id", type = "&i32"))]
1212
enum Node {
1313
MyObj(MyObj),
1414
}
@@ -48,7 +48,6 @@ pub async fn test_interface_simple_object() {
4848
pub async fn test_interface_simple_object2() {
4949
#[async_graphql::SimpleObject]
5050
struct MyObj {
51-
#[field(ref)]
5251
id: i32,
5352
title: String,
5453
}

tests/post_guard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl PostGuard<i32> for RoleGuard {
2424

2525
#[SimpleObject]
2626
struct MyObj {
27-
#[field(post_guard(UserGuard(username = r#""test""#, value = "88")))]
27+
#[field(owned, post_guard(UserGuard(username = r#""test""#, value = "88")))]
2828
value: i32,
2929
}
3030

tests/subscription.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub async fn test_subscription_fragment() {
324324
b: i32,
325325
}
326326

327-
#[Interface(field(name = "a", type = "i32"))]
327+
#[Interface(field(name = "a", type = "&i32"))]
328328
enum MyInterface {
329329
Event(Event),
330330
}
@@ -381,7 +381,7 @@ pub async fn test_subscription_fragment2() {
381381
b: i32,
382382
}
383383

384-
#[Interface(field(name = "a", type = "i32"))]
384+
#[Interface(field(name = "a", type = "&i32"))]
385385
enum MyInterface {
386386
Event(Event),
387387
}

tests/union.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub async fn test_union_simple_object() {
4848
pub async fn test_union_simple_object2() {
4949
#[async_graphql::SimpleObject]
5050
struct MyObj {
51-
#[field(ref)]
5251
id: i32,
5352
title: String,
5453
}

0 commit comments

Comments
 (0)