Skip to content

Commit 1eaf763

Browse files
authored
Added tests for schema keyword retention when description is present (#8354)
1 parent cd6bbc5 commit 1eaf763

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/HotChocolate/Language/test/Language.SyntaxTree.Tests/Utilities/SchemaSyntaxPrinterTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,35 @@ public void Serialize_SchemaDefWithOpNoIndent_InOutShouldBeTheSame()
716716
Assert.Equal(schema, result);
717717
}
718718

719+
[Fact]
720+
public void Serialize_SchemaDefWithDescriptionAndOps_SchemaKeywordNotOmitted()
721+
{
722+
// arrange
723+
var schema =
724+
"""
725+
"Example schema"
726+
schema {
727+
query: Query
728+
mutation: Mutation
729+
}
730+
731+
type Query {
732+
someField: String
733+
}
734+
735+
type Mutation {
736+
someMutation: String
737+
}
738+
""";
739+
var document = Utf8GraphQLParser.Parse(schema);
740+
741+
// act
742+
var result = document.ToString();
743+
744+
// assert
745+
result.MatchInlineSnapshot(schema);
746+
}
747+
719748
[Fact]
720749
public void Serialize_SchemaDefWithOpNoIndent_OutHasIndentation()
721750
{

src/HotChocolate/Mutable/test/Types.Mutable.Tests/SchemaFormatterTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,34 @@ input Bar {
293293
}
294294
""");
295295
}
296+
297+
[Fact]
298+
public void Format_Schema_With_Description_Schema_Keyword_Not_Omitted()
299+
{
300+
// arrange
301+
var sdl =
302+
"""
303+
"Example schema"
304+
schema {
305+
query: Query
306+
mutation: Mutation
307+
}
308+
309+
type Query {
310+
someField: String
311+
}
312+
313+
type Mutation {
314+
someMutation: String
315+
}
316+
""";
317+
318+
var schema = SchemaParser.Parse(Encoding.UTF8.GetBytes(sdl));
319+
320+
// act
321+
var formattedSdl = SchemaFormatter.FormatAsString(schema);
322+
323+
// assert
324+
formattedSdl.MatchInlineSnapshot(sdl);
325+
}
296326
}

0 commit comments

Comments
 (0)