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

Commit3001a02

Browse files
mythrnrsunli829
andauthored
fix: generate description of directives. (#1681)
* fix: generate description of directives.trigger actionfix: expected value of directive test. And use fixed version of poem for MSRV.fix: expected value of directive test.fix: expected value of directive test.fix: modify test fixtures.* fix tests---------Co-authored-by: Sunli <sunlipad4@icloud.com>Co-authored-by: Sunli <scott_s829@163.com>
1 parentfd48bc2 commit3001a02

11 files changed

+66
-9
lines changed

‎src/registry/export_sdl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl Registry {
186186
return;
187187
}
188188

189-
writeln!(sdl,"{}", directive.sdl()).ok();
189+
writeln!(sdl,"{}", directive.sdl(&options)).ok();
190190
});
191191

192192
if options.federation{
@@ -703,7 +703,7 @@ impl Registry {
703703
}
704704
}
705705

706-
fnwrite_description(
706+
pub(super)fnwrite_description(
707707
sdl:&mutString,
708708
options:&SDLExportOptions,
709709
level:usize,

‎src/registry/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,15 @@ pub struct MetaDirective {
727727
}
728728

729729
implMetaDirective{
730-
pub(crate)fnsdl(&self) ->String{
731-
letmut sdl =format!("directive @{}",self.name);
730+
pub(crate)fnsdl(&self,options:&SDLExportOptions) ->String{
731+
letmut sdl =String::new();
732+
733+
ifletSome(description) =&self.description{
734+
self::export_sdl::write_description(&mut sdl, options,0, description);
735+
}
736+
737+
write!(sdl,"directive @{}",self.name).ok();
738+
732739
if !self.args.is_empty(){
733740
let args =self
734741
.args
@@ -903,8 +910,8 @@ impl Registry {
903910
self.add_directive(MetaDirective{
904911
name:"oneOf".into(),
905912
description:Some(
906-
"Indicates that an Input Object is a OneOf Input Object (and thus requires
907-
exactly one of its field be provided)"
913+
"Indicates that an Input Object is a OneOf Input Object (and thus requires\
914+
exactly one of its field be provided)"
908915
.to_string(),
909916
),
910917
locations:vec![__DirectiveLocation::INPUT_OBJECT],

‎tests/directive.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub async fn test_directive_skip() {
2020
value5: value @skip(if: true)
2121
value6: value @skip(if: false)
2222
}
23-
23+
2424
query {
2525
value1: value @skip(if: true)
2626
value2: value @skip(if: false)
@@ -166,7 +166,13 @@ pub async fn test_includes_deprecated_directive() {
166166

167167
let schema =Schema::new(Query,EmptyMutation,EmptySubscription);
168168

169-
assert!(schema.sdl().contains(r#"directive @deprecated(reason: String = "No longer supported") on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE"#))
169+
assert!(schema.sdl().contains(
170+
r#"
171+
"""
172+
Marks an element of a GraphQL schema as no longer supported.
173+
"""
174+
directive @deprecated(reason: String = "No longer supported") on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE"#,
175+
))
170176
}
171177

172178
#[tokio::test]

‎tests/export_sdl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async fn test_spaces() {
3838
.sorted_fields()
3939
.sorted_enum_items(),
4040
);
41-
std::fs::write("./test_space_schema.graphql",&sdl).unwrap();
4241

4342
let expected =include_str!("schemas/test_space_schema.graphql");
4443
assert_eq!(sdl, expected);

‎tests/schemas/test_dynamic_schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ scalar TestScalar @json
3535

3636
unionTestUnion@wrap =OutputType |OutputType2
3737

38+
"""
39+
Directs the executor to include this field or fragment only when the `if` argument is true.
40+
"""
3841
directive@include(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
42+
"""
43+
Directs the executor to skip this field or fragment when the `if` argument is true.
44+
"""
3945
directive@skip(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
4046
schema {
4147
query:Query

‎tests/schemas/test_entity_inaccessible.schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ extend type Query {
6060
inaccessibleCustomObject:MyCustomObjInaccessible!
6161
}
6262

63+
"""
64+
Directs the executor to include this field or fragment only when the `if` argument is true.
65+
"""
6366
directive@include(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
67+
"""
68+
Directs the executor to skip this field or fragment when the `if` argument is true.
69+
"""
6470
directive@skip(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
6571
extendschema@link(
6672
url:"https://specs.apollo.dev/federation/v2.3",

‎tests/schemas/test_entity_tag.schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ extend type Query {
6060
taggedCustomObject:MyCustomObjTagged!
6161
}
6262

63+
"""
64+
Directs the executor to include this field or fragment only when the `if` argument is true.
65+
"""
6366
directive@include(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
67+
"""
68+
Directs the executor to skip this field or fragment when the `if` argument is true.
69+
"""
6470
directive@skip(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
6571
extendschema@link(
6672
url:"https://specs.apollo.dev/federation/v2.3",

‎tests/schemas/test_fed2_compose.schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ type Subscription @testDirective(scope: "object type", input: 3) {
1212
anotherValue:SimpleValue!
1313
}
1414

15+
"""
16+
Directs the executor to include this field or fragment only when the `if` argument is true.
17+
"""
1518
directive@include(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
1619
directive@noArgsDirectiveonFIELD_DEFINITION
20+
"""
21+
Directs the executor to skip this field or fragment when the `if` argument is true.
22+
"""
1723
directive@skip(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
1824
directive@testDirective(scope:String!,input:Int!,opt:Int)onFIELD_DEFINITION |OBJECT
1925
extendschema@link(

‎tests/schemas/test_fed2_compose_2.schema.graphql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ type TestSimpleObject @type_directive_object(description: "This is OBJECT in Sim
3939
field:String!@type_directive_field_definition(description:"This is FIELD_DEFINITION in SimpleObject")
4040
}
4141

42+
"""
43+
Directs the executor to include this field or fragment only when the `if` argument is true.
44+
"""
4245
directive@include(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
46+
"""
47+
Indicates that an Input Object is a OneOf Input Object (and thus requires exactly one of its field be provided)
48+
"""
4349
directive@oneOfonINPUT_OBJECT
50+
"""
51+
Directs the executor to skip this field or fragment when the `if` argument is true.
52+
"""
4453
directive@skip(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
4554
directive@type_directive_argument_definition(description:String!)onARGUMENT_DEFINITION
4655
directive@type_directive_enum(description:String!)onENUM

‎tests/schemas/test_fed2_link.schema.graphqls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ extend type User @key(fields: "id") {
1414
reviews: [Review!]!
1515
}
1616

17+
"""
18+
Directs the executor to include this field or fragment only when the `if` argument is true.
19+
"""
1720
directive@include(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
21+
"""
22+
Directs the executor to skip this field or fragment when the `if` argument is true.
23+
"""
1824
directive@skip(if:Boolean!)onFIELD |FRAGMENT_SPREAD |INLINE_FRAGMENT
1925
extendschema@link(
2026
url:"https://specs.apollo.dev/federation/v2.3",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp