Skip to content

Commit

Permalink
Introduce SDLPrinterOptions.PrintDescriptions (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored Apr 21, 2023
1 parent 20e9186 commit 0123f9d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<VersionPrefix>9.0.2-preview</VersionPrefix>
<VersionPrefix>9.1.0-preview</VersionPrefix>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);CA1707</NoWarn>
Expand Down
1 change: 1 addition & 0 deletions src/GraphQLParser.ApiTests/GraphQLParser.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ namespace GraphQLParser.Visitors
{
public SDLPrinterOptions() { }
public int IndentSize { get; set; }
public bool PrintDescriptions { get; set; }
public bool EachDirectiveLocationOnNewLine { get; init; }
public bool EachUnionMemberOnNewLine { get; init; }
public bool PrintComments { get; init; }
Expand Down
20 changes: 17 additions & 3 deletions src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ... on CustomerType {
@"directive @skip(if: Boolean!) on
| FIELD
| FRAGMENT_SPREAD
| INLINE_FRAGMENT", false, true)]
| INLINE_FRAGMENT", false, true, true)]
[InlineData(8,
@"directive @twoArgs
(a: Int, b:
Expand Down Expand Up @@ -488,7 +488,7 @@ union Unity
| B
extend union Unity =
| C", true, false, true)]
| C", true, true, false, true)]
[InlineData(38,
@"enum Color
#comment
Expand Down Expand Up @@ -574,7 +574,7 @@ directive @skip(
mutation: M
subscription: S
}
""", true, false, false, 5)]
""", true, true, false, false, 5)]
[InlineData(45,
"""
"A component contains the parametric details of a PCB part."
Expand Down Expand Up @@ -834,18 +834,32 @@ implements Entity &
name: String
}
""")]
[InlineData(58,
""""
"description"
type Person {
"""description"""
name: String }
"""",
"""
type Person {
name: String
}
""", false, false)]
public async Task SDLPrinter_Should_Print_Document(
int number,
string text,
string expected,
bool writeComments = true,
bool writeDescriptions = true,
bool eachDirectiveLocationOnNewLine = false,
bool eachUnionMemberOnNewLine = false,
int indentSize = 2)
{
var printer = new SDLPrinter(new SDLPrinterOptions
{
PrintComments = writeComments,
PrintDescriptions = writeDescriptions,
EachDirectiveLocationOnNewLine = eachDirectiveLocationOnNewLine,
EachUnionMemberOnNewLine = eachUnionMemberOnNewLine,
IndentSize = indentSize,
Expand Down
13 changes: 13 additions & 0 deletions src/GraphQLParser/Visitors/SDLPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ async ValueTask WriteMultilineBlockString()

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

if (!Options.PrintDescriptions)
return default;

// http://spec.graphql.org/October2021/#StringValue
return ShouldBeMultilineBlockString()
? WriteMultilineBlockString()
Expand Down Expand Up @@ -1111,21 +1114,31 @@ public class SDLPrinterOptions
{
/// <summary>
/// Print comments into the output.
/// By default <see langword="false"/>.
/// </summary>
public bool PrintComments { get; init; }

/// <summary>
/// Print descriptions into the output.
/// By default <see langword="true"/>.
/// </summary>
public bool PrintDescriptions { get; set; } = true;

/// <summary>
/// Whether to print each directive location on its own line.
/// By default <see langword="false"/>.
/// </summary>
public bool EachDirectiveLocationOnNewLine { get; init; }

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

/// <summary>
/// The size of the horizontal indentation in spaces.
/// By default 2.
/// </summary>
public int IndentSize { get; set; } = 2;
}
Expand Down

0 comments on commit 0123f9d

Please sign in to comment.