Add `SDLExportOptions::include_specified_by` method to enable `specifiedBy` directive #1065

This commit is contained in:
Sunli 2022-09-09 18:34:16 +08:00
parent b54f598501
commit f83d0a34d0
2 changed files with 19 additions and 7 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `no_cache` for `cache_control` attribute [#1051](https://github.com/async-graphql/async-graphql/issues/1051) - Add `no_cache` for `cache_control` attribute [#1051](https://github.com/async-graphql/async-graphql/issues/1051)
- Resurrect code generation through tests [#1062](https://github.com/async-graphql/async-graphql/pull/1062) - Resurrect code generation through tests [#1062](https://github.com/async-graphql/async-graphql/pull/1062)
- Support for primitive type in CursorType [#1049](https://github.com/async-graphql/async-graphql/pull/1049) - Support for primitive type in CursorType [#1049](https://github.com/async-graphql/async-graphql/pull/1049)
- Add `SDLExportOptions::include_specified_by` method to enable `specifiedBy` directive [#1065](https://github.com/async-graphql/async-graphql/issues/1065)
# [4.0.12] 2022-08-24 # [4.0.12] 2022-08-24

View File

@ -13,6 +13,7 @@ pub struct SDLExportOptions {
sorted_enum_values: bool, sorted_enum_values: bool,
federation: bool, federation: bool,
prefer_single_line_descriptions: bool, prefer_single_line_descriptions: bool,
include_specified_by: bool,
} }
impl SDLExportOptions { impl SDLExportOptions {
@ -71,6 +72,14 @@ impl SDLExportOptions {
..self ..self
} }
} }
/// Includes `specifiedBy` directive in SDL
pub fn include_specified_by(self) -> Self {
Self {
include_specified_by: true,
..self
}
}
} }
impl Registry { impl Registry {
@ -218,13 +227,15 @@ impl Registry {
} }
write!(sdl, "scalar {}", name).ok(); write!(sdl, "scalar {}", name).ok();
if let Some(specified_by_url) = specified_by_url { if options.include_specified_by {
write!( if let Some(specified_by_url) = specified_by_url {
sdl, write!(
" @specifiedBy(url: \"{}\")", sdl,
specified_by_url.replace('"', "\\\"") " @specifiedBy(url: \"{}\")",
) specified_by_url.replace('"', "\\\"")
.ok(); )
.ok();
}
} }
if options.federation { if options.federation {