Skip to content

Commit 0123f9d

Browse files
authored
Introduce SDLPrinterOptions.PrintDescriptions (#315)
1 parent 20e9186 commit 0123f9d

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<VersionPrefix>9.0.2-preview</VersionPrefix>
4+
<VersionPrefix>9.1.0-preview</VersionPrefix>
55
<LangVersion>latest</LangVersion>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
<NoWarn>$(NoWarn);CA1707</NoWarn>

src/GraphQLParser.ApiTests/GraphQLParser.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ namespace GraphQLParser.Visitors
909909
{
910910
public SDLPrinterOptions() { }
911911
public int IndentSize { get; set; }
912+
public bool PrintDescriptions { get; set; }
912913
public bool EachDirectiveLocationOnNewLine { get; init; }
913914
public bool EachUnionMemberOnNewLine { get; init; }
914915
public bool PrintComments { get; init; }

src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ ... on CustomerType {
123123
@"directive @skip(if: Boolean!) on
124124
| FIELD
125125
| FRAGMENT_SPREAD
126-
| INLINE_FRAGMENT", false, true)]
126+
| INLINE_FRAGMENT", false, true, true)]
127127
[InlineData(8,
128128
@"directive @twoArgs
129129
(a: Int, b:
@@ -488,7 +488,7 @@ union Unity
488488
| B
489489
490490
extend union Unity =
491-
| C", true, false, true)]
491+
| C", true, true, false, true)]
492492
[InlineData(38,
493493
@"enum Color
494494
#comment
@@ -574,7 +574,7 @@ directive @skip(
574574
mutation: M
575575
subscription: S
576576
}
577-
""", true, false, false, 5)]
577+
""", true, true, false, false, 5)]
578578
[InlineData(45,
579579
"""
580580
"A component contains the parametric details of a PCB part."
@@ -834,18 +834,32 @@ implements Entity &
834834
name: String
835835
}
836836
""")]
837+
[InlineData(58,
838+
""""
839+
"description"
840+
type Person {
841+
"""description"""
842+
name: String }
843+
"""",
844+
"""
845+
type Person {
846+
name: String
847+
}
848+
""", false, false)]
837849
public async Task SDLPrinter_Should_Print_Document(
838850
int number,
839851
string text,
840852
string expected,
841853
bool writeComments = true,
854+
bool writeDescriptions = true,
842855
bool eachDirectiveLocationOnNewLine = false,
843856
bool eachUnionMemberOnNewLine = false,
844857
int indentSize = 2)
845858
{
846859
var printer = new SDLPrinter(new SDLPrinterOptions
847860
{
848861
PrintComments = writeComments,
862+
PrintDescriptions = writeDescriptions,
849863
EachDirectiveLocationOnNewLine = eachDirectiveLocationOnNewLine,
850864
EachUnionMemberOnNewLine = eachUnionMemberOnNewLine,
851865
IndentSize = indentSize,

src/GraphQLParser/Visitors/SDLPrinter.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ async ValueTask WriteMultilineBlockString()
132132

133133
ValueTask WriteString() => WriteEncodedStringAsync(context, description.Value);
134134

135+
if (!Options.PrintDescriptions)
136+
return default;
137+
135138
// http://spec.graphql.org/October2021/#StringValue
136139
return ShouldBeMultilineBlockString()
137140
? WriteMultilineBlockString()
@@ -1111,21 +1114,31 @@ public class SDLPrinterOptions
11111114
{
11121115
/// <summary>
11131116
/// Print comments into the output.
1117+
/// By default <see langword="false"/>.
11141118
/// </summary>
11151119
public bool PrintComments { get; init; }
11161120

1121+
/// <summary>
1122+
/// Print descriptions into the output.
1123+
/// By default <see langword="true"/>.
1124+
/// </summary>
1125+
public bool PrintDescriptions { get; set; } = true;
1126+
11171127
/// <summary>
11181128
/// Whether to print each directive location on its own line.
1129+
/// By default <see langword="false"/>.
11191130
/// </summary>
11201131
public bool EachDirectiveLocationOnNewLine { get; init; }
11211132

11221133
/// <summary>
11231134
/// Whether to print each union member on its own line.
1135+
/// By default <see langword="false"/>.
11241136
/// </summary>
11251137
public bool EachUnionMemberOnNewLine { get; init; }
11261138

11271139
/// <summary>
11281140
/// The size of the horizontal indentation in spaces.
1141+
/// By default 2.
11291142
/// </summary>
11301143
public int IndentSize { get; set; } = 2;
11311144
}

0 commit comments

Comments
 (0)