Skip to content

Commit 0f98c45

Browse files
committed
Cover arguments in codegen docs
1 parent f7717fd commit 0f98c45

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

juniper_codegen/src/lib.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ pub fn derive_scalar_value(input: TokenStream) -> TokenStream {
10041004
/// The description of [GraphQL interface][1], its field, or a field argument may be specified
10051005
/// either with a `description`/`desc` attribute's argument, or with a regular Rust doc comment.
10061006
///
1007-
/// A field of [GraphQL interface][1] may be deprecated by specifying a `deprecated` attribute's
1008-
/// argument, or with regular Rust `#[deprecated]` attribute.
1007+
/// A field (or its argument) of [GraphQL interface][1] may be deprecated by specifying a
1008+
/// `deprecated` attribute's argument, or with the regular Rust `#[deprecated]` attribute.
10091009
///
10101010
/// The default value of a field argument may be specified with a `default` attribute argument (if
10111011
/// no exact value is specified then [`Default::default`] is used).
@@ -1014,25 +1014,43 @@ pub fn derive_scalar_value(input: TokenStream) -> TokenStream {
10141014
/// # use juniper::graphql_interface;
10151015
/// #
10161016
/// #[graphql_interface]
1017-
/// #[graphql(name = "Character", desc = "Possible episode characters.")]
1017+
/// #[graphql(
1018+
/// // Rename the type for GraphQL by specifying the name here.
1019+
/// name = "Character",
1020+
/// // You may also specify a description here.
1021+
/// // If present, doc comments will be ignored.
1022+
/// desc = "Possible episode characters.",
1023+
/// )]
10181024
/// trait Chrctr {
10191025
/// #[graphql(name = "id", desc = "ID of the character.")]
10201026
/// #[graphql(deprecated = "Don't use it")]
10211027
/// fn some_id(
10221028
/// &self,
10231029
/// #[graphql(name = "number", desc = "Arbitrary number.")]
1030+
/// // You may specify default values.
1031+
/// // A default can be any valid expression that yields the right type.
10241032
/// #[graphql(default = 5)]
10251033
/// num: i32,
10261034
/// ) -> &str;
10271035
/// }
10281036
///
1029-
/// // NOTICE: Rust docs are used as GraphQL description.
1037+
/// // Rust docs are used as GraphQL description.
10301038
/// /// Possible episode characters.
10311039
/// #[graphql_interface]
10321040
/// trait CharacterWithDocs {
1041+
/// // Doc comments also work on fields.
10331042
/// /// ID of the character.
1043+
/// // If no explicit deprecation reason is provided,
1044+
/// // then the default "No longer supported" one is used.
10341045
/// #[deprecated]
1035-
/// fn id(&self, #[graphql(default)] num: i32) -> &str;
1046+
/// fn id(
1047+
/// &self,
1048+
/// // If expression is not specified then `Default::default()` is used.
1049+
/// #[graphql(default, deprecated)] num: i32,
1050+
/// // Only `Null`able arguments or non-`Null` arguments with default values
1051+
/// // can be deprecated.
1052+
/// #[graphql(deprecated)] modifier: Option<f64>,
1053+
/// ) -> &str;
10361054
/// }
10371055
/// ```
10381056
///
@@ -1652,9 +1670,8 @@ pub fn derive_object(body: TokenStream) -> TokenStream {
16521670
/// be specified either with a `description`/`desc` attribute's argument, or
16531671
/// with a regular Rust doc comment.
16541672
///
1655-
/// A field of [GraphQL object][1] may be deprecated by specifying a
1656-
/// `deprecated` attribute's argument, or with regular Rust `#[deprecated]`
1657-
/// attribute.
1673+
/// A field (or its argument) of [GraphQL object][1] may be deprecated by specifying a `deprecated`
1674+
/// attribute's argument, or with the regular Rust `#[deprecated]` attribute.
16581675
///
16591676
/// The default value of a field argument may be specified with a `default`
16601677
/// attribute argument (if no exact value is specified then [`Default::default`]
@@ -1696,11 +1713,16 @@ pub fn derive_object(body: TokenStream) -> TokenStream {
16961713
/// impl HumanWithDocs {
16971714
/// // Doc comments also work on fields.
16981715
/// /// ID of the human.
1716+
/// // If no explicit deprecation reason is provided,
1717+
/// // then the default "No longer supported" one is used.
16991718
/// #[deprecated]
17001719
/// fn id(
17011720
/// &self,
17021721
/// // If expression is not specified then `Default::default()` is used.
1703-
/// #[graphql(default)] num: i32,
1722+
/// #[graphql(default, deprecated)] num: i32,
1723+
/// // Only `Null`able arguments or non-`Null` arguments with default values
1724+
/// // can be deprecated.
1725+
/// #[graphql(deprecated)] modifier: Option<f64>,
17041726
/// ) -> &str {
17051727
/// "Deprecated"
17061728
/// }

0 commit comments

Comments
 (0)