diff --git a/src/Directory.Build.props b/src/Directory.Build.props index dac567bd..1b9391d7 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ - 9.0.1-preview + 9.0.2-preview latest true $(NoWarn);CA1707 diff --git a/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs b/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs index d650eca9..4b8118ac 100644 --- a/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs +++ b/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs @@ -409,8 +409,8 @@ type Dog implements Animal #arguments comment #multilined (x: 10, y: { - #comment on object field - z: 1}) + #comment on object field + z: 1}) }")] [InlineData(33, @"{ @@ -519,8 +519,8 @@ extend enum Color }", @"type T { data( - #comment - rendered: Boolean): String + #comment + rendered: Boolean): String }", true)] [InlineData(40, """ "This is a Foo object type" @@ -654,6 +654,142 @@ query q( schema { query: Query } +""")] + [InlineData(50, +""" +type Query { +"Fetches an object given its ID." +node( +"ID of the object." +id: ID!): Node +"Lookup nodes by a list of IDs." +nodes( +"The list of node IDs." +ids: [ID!]!): [Node]! +"Search for workspaces associated with this account." +desWorkspaces(where: DesWorkspaceFilterInput): [DesWorkspace!]! +"Search a specific workspace by its unique identifier." +desWorkspaceById( +"The node identifier for a workspace." id: ID!): DesWorkspace +} +""", +""" +type Query { + "Fetches an object given its ID." + node( + "ID of the object." + id: ID!): Node + "Lookup nodes by a list of IDs." + nodes( + "The list of node IDs." + ids: [ID!]!): [Node]! + "Search for workspaces associated with this account." + desWorkspaces(where: DesWorkspaceFilterInput): [DesWorkspace!]! + "Search a specific workspace by its unique identifier." + desWorkspaceById( + "The node identifier for a workspace." + id: ID!): DesWorkspace +} +""")] + [InlineData(51, +""" +type Query { + user + # comment 1 + ( + # comment 2 + id: ID! + name: Name!): Node +} +""", +""" +type Query { + user + # comment 1 + ( + # comment 2 + id: ID!, name: Name!): Node +} +""")] + [InlineData(52, +""" +directive @my + # comment 1 + ( + # comment 2 + arg: Boolean!) on FIELD +""", +""" +directive @my + # comment 1 + ( + # comment 2 + arg: Boolean!) on FIELD +""")] + [InlineData(53, +""" +query Q { + field1(arg1: 1) { + field2(arg2: 2) { + field3(arg3: 3) + } + } +} +""", +""" +query Q { + field1(arg1: 1) { + field2(arg2: 2) { + field3(arg3: 3) + } + } +} +""")] + [InlineData(54, +""" +query Q { + field1 + #comment + ( + #comment + arg1: 1 + ) { + field2 + #comment + ( + #comment + arg2: 2 + ) { + field3 + #comment + ( + #comment + arg3: 3 + ) + } + } +} +""", +""" +query Q { + field1 + #comment + ( + #comment + arg1: 1) { + field2 + #comment + ( + #comment + arg2: 2) { + field3 + #comment + ( + #comment + arg3: 3) + } + } +} """)] public async Task SDLPrinter_Should_Print_Document( int number, diff --git a/src/GraphQLParser/Visitors/SDLPrinter.cs b/src/GraphQLParser/Visitors/SDLPrinter.cs index deaa6e57..1f85c8ec 100644 --- a/src/GraphQLParser/Visitors/SDLPrinter.cs +++ b/src/GraphQLParser/Visitors/SDLPrinter.cs @@ -721,7 +721,7 @@ protected override async ValueTask VisitArgumentAsync(GraphQLArgument argument, protected override async ValueTask VisitArgumentsDefinitionAsync(GraphQLArgumentsDefinition argumentsDefinition, TContext context) { await VisitAsync(argumentsDefinition.Comments, context).ConfigureAwait(false); - await context.WriteAsync("(").ConfigureAwait(false); + await VisitAsync(LiteralNode.Wrap("("), context).ConfigureAwait(false); foreach (var argumentDefinition in argumentsDefinition.Items) await VisitAsync(argumentDefinition, context).ConfigureAwait(false); @@ -870,23 +870,26 @@ public override async ValueTask VisitAsync(ASTNode? node, TContext context) int prevLevel = context.IndentLevel; - if ( - ( - node is GraphQLInputValueDefinition || - node is GraphQLFieldDefinition || - node is GraphQLEnumValueDefinition || - node is GraphQLRootOperationTypeDefinition || - node is GraphQLDirectiveLocations && Options.EachDirectiveLocationOnNewLine || - node is GraphQLUnionMemberTypes && Options.EachUnionMemberOnNewLine - ) && context.Parents.Count > 0 - ) - context.IndentLevel = 1; // fixed indentation of 1 - else if ( - node is GraphQLField || - node is GraphQLFragmentSpread || - node is GraphQLInlineFragment - ) - ++context.IndentLevel; // nested indentation + if (context.Parents.Count > 0) + { + if ( + node is GraphQLFieldDefinition || + node is GraphQLEnumValueDefinition || + node is GraphQLRootOperationTypeDefinition || + node is GraphQLDirectiveLocations && Options.EachDirectiveLocationOnNewLine || + node is GraphQLUnionMemberTypes && Options.EachUnionMemberOnNewLine || + node is GraphQLArgumentsDefinition && node.Comments?.Count > 0 + ) + context.IndentLevel = 1; // fixed indentation of 1 + else if ( + node is GraphQLField || + node is GraphQLFragmentSpread || + node is GraphQLInlineFragment || + node is GraphQLArgument || + node is GraphQLInputValueDefinition + ) + ++context.IndentLevel; // nested indentation + } context.Parents.Push(node);