Skip to content

Commit

Permalink
Fix schema builder so it reads schema descriptions (#3666)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Jul 23, 2023
1 parent 62f38bf commit ad9286e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/GraphQL.Tests/Utilities/SchemaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,49 @@ namespace GraphQL.Tests.Utilities;

public class SchemaBuilderTests
{
[Theory]
[InlineData(false)]
[InlineData(true)]
public void should_read_schema_description(bool ignoreComments)
{
const string definitions = """
#test
"Sample schema"
schema {
query: Query
}
"Sample query"
type Query {
id: String
}
""";

var schema = Schema.For(definitions, c => c.IgnoreComments = ignoreComments);
schema.Initialize();

schema.Description.ShouldBe("Sample schema");
}

[Fact]
public void should_read_schema_description_from_comments()
{
const string definitions = """
#test
schema {
query: Query
}
"Sample query"
type Query {
id: String
}
""";

var schema = Schema.For(definitions, c => c.IgnoreComments = false);
schema.Initialize();

schema.Description.ShouldBe("test");
}

[Fact]
public void should_set_query_by_name()
{
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/Utilities/SchemaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private Schema BuildSchemaFrom(GraphQLDocument document)

if (_schemaDef != null)
{
schema.Description = _schemaDef.MergeComments();
schema.Description = _schemaDef.Description?.Value.ToString() ?? _schemaDef.MergeComments();

foreach (var operationTypeDef in _schemaDef.OperationTypes!)
{
Expand Down

0 comments on commit ad9286e

Please sign in to comment.