Skip to content

Commit

Permalink
Add tests for no indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Dec 21, 2023
1 parent 64985e1 commit c97d972
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 40 deletions.
70 changes: 46 additions & 24 deletions src/HotChocolate/Core/test/Types.Tests/Types/DescriptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Threading.Tasks;
using CookieCrumble;
using HotChocolate.Execution;
using HotChocolate.Language;
using HotChocolate.Language.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Snapshooter.Xunit;

namespace HotChocolate.Types;

Expand All @@ -13,31 +12,28 @@ public class DescriptionTests
public async Task Schema_With_All_Possible_Descriptions()
{
// arrange
var schema = await new ServiceCollection()
.AddGraphQL()
.ModifyOptions(o =>
{
o.RemoveUnreachableTypes = false;
o.RemoveUnusedTypeSystemDirectives = false;
})
.SetSchema(d => d.Description("Single line comment"))
.AddQueryType<Query>()
.AddInterfaceType<ISomeInterface>()
.AddInterfaceType<IOtherInterface>()
.AddObjectType<OtherObjectType>()
.AddUnionType<ISomeUnion>()
.AddUnionType<IOtherUnion>()
.AddDirectiveType<SomeDirective>()
.AddDirectiveType<OtherDirective>()
.AddType<SomeEnum>()
.AddType<OtherEnum>()
.AddType<SomeScalar>()
.AddType<OtherScalar>()
.BuildSchemaAsync();
var schema = await GetSchemaWithAllPossibleDescriptionsAsync();

// act
// assert
SchemaPrinter
.PrintSchema(schema)
.Print(indented: true)
.MatchSnapshot(extension: ".graphql");
}

[Fact]
public async Task Schema_With_All_Possible_Descriptions_No_Indent()
{
// arrange
var schema = await GetSchemaWithAllPossibleDescriptionsAsync();

// act
// assert
SnapshotExtension.MatchSnapshot(schema.ToString());
SchemaPrinter
.PrintSchema(schema)
.Print(indented: false)
.MatchSnapshot(extension: ".graphql");
}

[Fact]
Expand Down Expand Up @@ -214,6 +210,32 @@ type Query {
"""");
}

private static async Task<ISchema> GetSchemaWithAllPossibleDescriptionsAsync()
{
return await new ServiceCollection()
.AddGraphQL()
.ModifyOptions(o =>
{
o.RemoveUnreachableTypes = false;
o.RemoveUnusedTypeSystemDirectives = false;
o.EnableTag = false;
})
.SetSchema(d => d.Description("Single line comment"))
.AddQueryType<Query>()
.AddInterfaceType<ISomeInterface>()
.AddInterfaceType<IOtherInterface>()
.AddObjectType<OtherObjectType>()
.AddUnionType<ISomeUnion>()
.AddUnionType<IOtherUnion>()
.AddDirectiveType<SomeDirective>()
.AddDirectiveType<OtherDirective>()
.AddType<SomeEnum>()
.AddType<OtherEnum>()
.AddType<SomeScalar>()
.AddType<OtherScalar>()
.BuildSchemaAsync();
}

[GraphQLDescription("""
Multi line
comment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"Single line comment"
"Single line comment"
schema {
query: Query
}
Expand Down Expand Up @@ -128,25 +128,11 @@ Multi line
comment
""" arg2: String) on FIELD

"""
The @tag directive is used to apply arbitrary string
metadata to a schema location. Custom tooling can use
this metadata during any step of the schema delivery flow,
including composition, static analysis, and documentation.

interface Book {
id: ID! @tag(name: "your-value")
title: String!
author: String!
}
"""
directive @tag("The name of the tag." name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"""
Multi line
comment
"""
scalar Other

"Single line comment"
scalar Some
scalar Some
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"Single line comment" schema { query: Query } "Single line comment" interface OtherInterface { field: String } """
Multi line
comment
""" interface SomeInterface { "Single line comment" field: String """
Multi line
comment
""" fieldMulti: String fieldWithArgs("Single line comment" arg1: String """
Multi line
comment
""" arg2: String): String } """
Multi line
comment
""" type OtherObjectType implements SomeInterface & OtherInterface { field: String fieldMulti: String fieldWithArgs(arg1: String arg2: String): String } """
Multi line
comment
""" type Query { "Single line comment" outputFieldSingle: String """
Multi line
comment
""" outputFieldMulti: String outputFieldWithArgs("Single line comment" arg1: SomeInput """
Multi line
comment
""" arg2: OtherInput): String } "Single line comment" union OtherUnion = OtherObjectType """
Multi line
comment
""" union SomeUnion = OtherObjectType "Single line comment" input OtherInput { "Single line comment" field: String """
Multi line
comment
""" fieldMulti: String } """
Multi line
comment
""" input SomeInput { "Single line comment" field: String """
Multi line
comment
""" fieldMulti: String } """
Multi line
comment
""" enum OtherEnum { "Single line comment" VALUE1 """
Multi line
comment
""" VALUE2 } "Single line comment" enum SomeEnum { "Single line comment" VALUE1 """
Multi line
comment
""" VALUE2 } "Single line comment" directive @other("Single line comment" arg1: String """
Multi line
comment
""" arg2: String) on FIELD """
Multi line
comment
""" directive @some("Single line comment" arg1: String """
Multi line
comment
""" arg2: String) on FIELD """
Multi line
comment
""" scalar Other "Single line comment" scalar Some

0 comments on commit c97d972

Please sign in to comment.