diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index bde6f82d..e596f820 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -19,7 +19,7 @@ jobs: show-progress: false - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 7.0.x diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 30ef4f73..421efaf5 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -15,7 +15,7 @@ jobs: label: runs-on: ubuntu-latest steps: - - uses: actions/labeler@v4 + - uses: actions/labeler@v5 with: sync-labels: "" repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 92da5134..c5eaa3db 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -25,7 +25,7 @@ jobs: with: show-progress: false - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 7.0.x source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 2f32eade..f39ce602 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -31,7 +31,7 @@ jobs: echo version=$version echo "version=$version" >> $GITHUB_ENV - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 7.0.x source-url: https://api.nuget.org/v3/index.json @@ -56,7 +56,7 @@ jobs: working-directory: src run: dotnet nuget push "out/*" -k ${{secrets.NUGET_AUTH_TOKEN}} - name: Upload Nuget packages as release artifacts - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fba533a4..6b85b1b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: with: show-progress: false - name: Setup .NET SDKs - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 3.1.x diff --git a/src/Directory.Build.props b/src/Directory.Build.props index eac42719..6f1dad1b 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -31,7 +31,7 @@ - + diff --git a/src/GraphQLParser.ApiTests/GraphQLParser.ApiTests.csproj b/src/GraphQLParser.ApiTests/GraphQLParser.ApiTests.csproj index c63c9328..766a3497 100644 --- a/src/GraphQLParser.ApiTests/GraphQLParser.ApiTests.csproj +++ b/src/GraphQLParser.ApiTests/GraphQLParser.ApiTests.csproj @@ -7,9 +7,9 @@ - + - + diff --git a/src/GraphQLParser.Benchmarks/GraphQLParser.Benchmarks.csproj b/src/GraphQLParser.Benchmarks/GraphQLParser.Benchmarks.csproj index 8ed5cfcf..bd2034d8 100644 --- a/src/GraphQLParser.Benchmarks/GraphQLParser.Benchmarks.csproj +++ b/src/GraphQLParser.Benchmarks/GraphQLParser.Benchmarks.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/GraphQLParser.Tests/GraphQLParser.Tests.csproj b/src/GraphQLParser.Tests/GraphQLParser.Tests.csproj index 1ad7dd27..3939cb1c 100644 --- a/src/GraphQLParser.Tests/GraphQLParser.Tests.csproj +++ b/src/GraphQLParser.Tests/GraphQLParser.Tests.csproj @@ -26,7 +26,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs b/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs index c3486762..122e31a8 100644 --- a/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs +++ b/src/GraphQLParser.Tests/Visitors/SDLPrinterFromParsedTextTests.cs @@ -1060,6 +1060,17 @@ public void UTF8_MemoryStream_Runs_Synchronously() printer.PrintAsync(document, writer).IsCompletedSuccessfully.ShouldBeTrue(); } + [Theory] + [InlineData("{ field1 }", "{\n field1\n}")] + [InlineData("query { field1 }", "{\n field1\n}")] + [InlineData("query q1 { field1 }", "query q1 {\n field1\n}")] + [InlineData("mutation { field1 }", "mutation {\n field1\n}")] + [InlineData("mutation m1 { field1 }", "mutation m1 {\n field1\n}")] + public void OperationPrints(string input, string expected) + { + new SDLPrinter().Print(Parser.Parse(input)).ShouldBe(expected, StringCompareShould.IgnoreLineEndings); + } + [Theory] [InlineData("query a { name }")] [InlineData("directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT")] diff --git a/src/GraphQLParser/Visitors/SDLPrinter.cs b/src/GraphQLParser/Visitors/SDLPrinter.cs index d21a03ba..02dbe903 100644 --- a/src/GraphQLParser/Visitors/SDLPrinter.cs +++ b/src/GraphQLParser/Visitors/SDLPrinter.cs @@ -262,11 +262,14 @@ protected override async ValueTask VisitFieldAsync(GraphQLField field, TContext protected override async ValueTask VisitOperationDefinitionAsync(GraphQLOperationDefinition operationDefinition, TContext context) { await VisitAsync(operationDefinition.Comments, context).ConfigureAwait(false); - if (operationDefinition.Name is not null) + if (operationDefinition.Name is not null || operationDefinition.Operation != OperationType.Query) { await VisitAsync(LiteralNode.Wrap(GetOperationType(operationDefinition.Operation)), context).ConfigureAwait(false); await context.WriteAsync(" ").ConfigureAwait(false); - await VisitAsync(operationDefinition.Name, context).ConfigureAwait(false); + if (operationDefinition.Name is not null) + { + await VisitAsync(operationDefinition.Name, context).ConfigureAwait(false); + } } await VisitAsync(operationDefinition.Variables, context).ConfigureAwait(false); await VisitAsync(operationDefinition.Directives, context).ConfigureAwait(false);