From f6c0c338854b4eb7316a9c86e263b4f0106d062c Mon Sep 17 00:00:00 2001 From: Sunli Date: Tue, 9 Mar 2021 15:12:14 +0800 Subject: [PATCH] Add `extends` attribute for derive macros Subscription and MergedSubscription. --- CHANGELOG.md | 1 + derive/src/args.rs | 3 +++ derive/src/merged_subscription.rs | 3 ++- derive/src/subscription.rs | 3 ++- src/lib.rs | 5 ++++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f59a2fd9..0cf01b3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove unnecessary Box from WebSocket messages. - Export subscription type to Federation SDL. (for [GraphGate](https://github.com/async-graphql/graphgate) 😁) +- Add `extends` attribute for derive macros Subscription and MergedSubscription. ## [2.5.11] - 2021-03-07 diff --git a/derive/src/args.rs b/derive/src/args.rs index 0fbc861e..c58ac47d 100644 --- a/derive/src/args.rs +++ b/derive/src/args.rs @@ -427,6 +427,7 @@ pub struct Subscription { pub rename_fields: Option, pub rename_args: Option, pub use_type_description: bool, + pub extends: bool, } #[derive(FromMeta, Default)] @@ -497,6 +498,8 @@ pub struct MergedSubscription { pub name: Option, #[darling(default)] pub visible: Option, + #[darling(default)] + pub extends: bool, } #[derive(Debug, Copy, Clone, FromMeta)] diff --git a/derive/src/merged_subscription.rs b/derive/src/merged_subscription.rs index 936d00f3..6b912426 100644 --- a/derive/src/merged_subscription.rs +++ b/derive/src/merged_subscription.rs @@ -10,6 +10,7 @@ use crate::utils::{get_crate_name, get_rustdoc, visible_fn, GeneratorResult}; pub fn generate(object_args: &args::MergedSubscription) -> GeneratorResult { let crate_name = get_crate_name(object_args.internal); let ident = &object_args.ident; + let extends = object_args.extends; let gql_typename = object_args .name .clone() @@ -68,7 +69,7 @@ pub fn generate(object_args: &args::MergedSubscription) -> GeneratorResult GeneratorResult { let crate_name = get_crate_name(subscription_args.internal); let (self_ty, self_name) = get_type_path_and_name(item_impl.self_ty.as_ref())?; + let extends = subscription_args.extends; let gql_typename = subscription_args .name @@ -441,7 +442,7 @@ pub fn generate( fields }, cache_control: ::std::default::Default::default(), - extends: false, + extends: #extends, keys: ::std::option::Option::None, visible: ::std::option::Option::None, }) diff --git a/src/lib.rs b/src/lib.rs index 34ff8d78..f0ed14a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -825,6 +825,7 @@ pub use async_graphql_derive::Union; /// | name | Object name | string | Y | /// | rename_fields | Rename all the fields according to the given case convention. The possible values are "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE".| string | Y | /// | rename_args | Rename all the arguments according to the given case convention. The possible values are "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE".| string | Y | +/// | extends | Add fields to an entity that's defined in another service | bool | Y | /// | use_type_description | Specifies that the description of the type is on the type declaration. [`Description`]()(derive.Description.html) | bool | Y | /// /// # Field parameters @@ -945,7 +946,6 @@ pub use async_graphql_derive::NewType; /// | name | Object name | string | Y | /// | cache_control | Object cache control | [`CacheControl`](struct.CacheControl.html) | Y | /// | extends | Add fields to an entity that's defined in another service | bool | Y | -/// | use_type_description | Specifies that the description of the type is on the type declaration. [`Description`]()(derive.Description.html) | bool | Y | /// | visible | If `false`, it will not be displayed in introspection. *[See also the Book](https://async-graphql.github.io/async-graphql/en/visibility.html).* | bool | Y | /// | visible | Call the specified function. If the return value is `false`, it will not be displayed in introspection. | string | Y | /// @@ -985,6 +985,9 @@ pub use async_graphql_derive::MergedObject; /// | Attribute | description | Type | Optional | /// |---------------|---------------------------|----------|----------| /// | name | Object name | string | Y | +/// | extends | Add fields to an entity that's defined in another service | bool | Y | +/// | visible | If `false`, it will not be displayed in introspection. *[See also the Book](https://async-graphql.github.io/async-graphql/en/visibility.html).* | bool | Y | +/// | visible | Call the specified function. If the return value is `false`, it will not be displayed in introspection. | string | Y | /// /// # Examples ///