Skip to content

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Aug 18, 2024
2 parents edc321a + b201d09 commit 97d7207
Show file tree
Hide file tree
Showing 32 changed files with 601 additions and 166 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ jobs:

steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
show-progress: false

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
show-progress: false
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout source
uses: actions/checkout@v4
with:
show-progress: false
- name: Check github.ref starts with 'refs/tags/'
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: |
Expand All @@ -28,9 +31,9 @@ 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
dotnet-version: 8.0.x
source-url: https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.NUGET_AUTH_TOKEN}}
Expand All @@ -53,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: |
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master
- develop
- v8
- v8
paths:
- src/**
- .github/workflows/**
Expand All @@ -31,21 +31,19 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
show-progress: false
- name: Setup .NET SDKs
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
7.0.x
8.0.x
source-url: https://nuget.pkg.github.com/graphql-dotnet/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Disable MSVS Nuget Source # see https://github.com/graphql-dotnet/graphql-dotnet/issues/2422
if: ${{ startsWith(matrix.os, 'windows') }}
run: dotnet nuget disable source 'Microsoft Visual Studio Offline Packages'
- name: Install dependencies
working-directory: src
run: dotnet restore
Expand All @@ -72,7 +70,7 @@ jobs:
if: ${{ startsWith(matrix.os, 'ubuntu') }}
uses: codecov/codecov-action@v3
with:
files: .coverage/GraphQLParser.Tests/coverage.net5.opencover.xml
files: .coverage/GraphQLParser.Tests/coverage.net8.opencover.xml

buildcheck:
needs:
Expand Down
94 changes: 79 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
[![License](https://img.shields.io/github/license/graphql-dotnet/parser)](LICENSE.md)
[![codecov](https://codecov.io/gh/graphql-dotnet/parser/branch/master/graph/badge.svg?token=GEjwg1by60)](https://codecov.io/gh/graphql-dotnet/parser)
[![Nuget](https://img.shields.io/nuget/dt/GraphQL-Parser)](https://www.nuget.org/packages/GraphQL-Parser)
[![NuGet](https://img.shields.io/nuget/v/GraphQL-Parser.svg)](https://www.nuget.org/packages/GraphQL-Parser)
[![Nuget](https://img.shields.io/nuget/v/GraphQL-Parser)](https://www.nuget.org/packages/GraphQL-Parser)
[![GitHub Release Date](https://img.shields.io/github/release-date/graphql-dotnet/parser?label=released)](https://github.com/graphql-dotnet/parser/releases)
[![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/graphql-dotnet/parser/latest?label=new+commits)](https://github.com/graphql-dotnet/parser/commits/master)
![Size](https://img.shields.io/github/repo-size/graphql-dotnet/parser)

[![GitHub contributors](https://img.shields.io/github/contributors/graphql-dotnet/parser)](https://github.com/graphql-dotnet/parser/graphs/contributors)
![Activity](https://img.shields.io/github/commit-activity/w/graphql-dotnet/parser)
![Activity](https://img.shields.io/github/commit-activity/m/graphql-dotnet/parser)
![Activity](https://img.shields.io/github/commit-activity/y/graphql-dotnet/parser)
![Size](https://img.shields.io/github/repo-size/graphql-dotnet/parser)

This library contains a lexer and parser as well as the complete [GraphQL AST model](http://spec.graphql.org/October2021/#sec-Appendix-Grammar-Summary)
that allows you to work with GraphQL documents compatible with the [October 2021 spec](https://spec.graphql.org/October2021/).
Expand All @@ -26,7 +22,7 @@ Preview versions of this package are available on [GitHub Packages](https://gith
Generates token based on input text. Lexer takes advantage of `ReadOnlyMemory<char>` and in most cases
does not allocate memory on the managed heap at all.

### Usage
Usage:

```csharp
var token = Lexer.Lex("\"str\"");
Expand All @@ -40,7 +36,7 @@ Lex method always returns the first token it finds. In this case case the result
Parses provided GraphQL expression into AST (abstract syntax tree). Parser also takes advantage of
`ReadOnlyMemory<char>` but still allocates memory for AST.

### Usage
Usage:

```csharp
var ast1 = Parser.Parse(@"
Expand Down Expand Up @@ -78,15 +74,83 @@ Default implementation traverses all AST nodes of the provided one. You can
inherit from it and override desired methods to implement your own AST
processing algorithm.

### SDLPrinter

For printing SDL from AST, you can use `SDLPrinter`. This is a highly
optimized visitor for asynchronous non-blocking SDL output into provided
`TextWriter`. In the majority of cases it does not allocate memory in
the managed heap at all.
the managed heap at all. Extension methods are also provided for printing
directly to a string, which utilize the `StringBuilder` and `StringWriter`
classes.

```csharp
var document = Parser.Parse("query { hero { name age } }");

// print to a string with default options
var sdl = new SDLPrinter().Print(document);

// print to a string builder
var sb = new StringBuilder();
new SDLPrinter().Print(document, sb);

// print to a string with some options
var sdlPrinter = new SDLPrinter(
new SDLPrinterOptions
{
PrintComments = true,
EachDirectiveLocationOnNewLine = true,
EachUnionMemberOnNewLine = true,
});
var sdl = sdlPrinter.Print(document);

// print to a stream asynchronously
using var writer = new StreamWriter(stream);
await sdlPrinter.PrintAsync(document, writer, default);
await writer.FlushAsync();
```

Output:

```graphql
query {
hero {
name
age
}
}
```

### SDLSorter

An AST document can be sorted with the `SDLSorter` using a predefined
sort order. You can specify the string comparison; by default it uses
a culture-invariant case-insensitive comparison. Any futher customization
is possible by deriving from `SDLSorterOptions` and overriding the `Compare`
methods.

```csharp
var document = Parser.Parse("query { hero { name age } }");
SDLSorter.Sort(document);
var sdl = new SDLPrinter().Print(document);
```

Output:

```graphql
query {
hero {
age
name
}
}
```

### StructurePrinter

You can also find a `StructurePrinter` visitor that prints AST into the
provided `TextWriter` as a hierarchy of node types. It can be useful
when debugging for better understanding the AST structure.
Consider GraphQL document
Consider the following GraphQL document:

```graphql
query a { name age }
Expand All @@ -105,14 +169,14 @@ Document
Name [age]
```

### Usage
Usage:

```csharp
public static async Task Print(string text)
public static async Task PrintStructure(string sdl)
{
using var document = Parser.Parse(text);
var writer = new StringWriter();
var printer = new SDLPrinter()
var document = Parser.Parse(sdl);
using var writer = new StringWriter();
var printer = new StructurePrinter()
await printer.PrintAsync(document, writer);
var rendered = writer.ToString();
Console.WriteLine(rendered);
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<VersionPrefix>9.2.0-preview</VersionPrefix>
<VersionPrefix>9.3.0-preview</VersionPrefix>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);CA1707</NoWarn>
Expand Down Expand Up @@ -31,7 +31,7 @@
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<None Include="..\..\assets\logo.64x64.png" Pack="true" PackagePath="\" Visible="false" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" Visible="false" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/GraphQLParser.ApiTests/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Public_Api_Should_Not_Change_Inadvertently(Type type)
{
IncludeAssemblyAttributes = false,
//WhitelistedNamespacePrefixes = new[] { "Microsoft.Extensions.DependencyInjection" },
ExcludeAttributes = new[] { "System.Diagnostics.DebuggerDisplayAttribute", "System.Diagnostics.CodeAnalysis.AllowNullAttribute" }
ExcludeAttributes = ["System.Diagnostics.DebuggerDisplayAttribute", "System.Diagnostics.CodeAnalysis.AllowNullAttribute"]
}))).ToArray();

if (publicApi.DistinctBy(item => item.content).Count() == 1)
Expand Down
10 changes: 5 additions & 5 deletions src/GraphQLParser.ApiTests/GraphQLParser.ApiTests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7</TargetFramework>
<TargetFramework>net8</TargetFramework>
<NoWarn>$(NoWarn);1591</NoWarn>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5" />
<PackageReference Include="PublicApiGenerator" Version="11.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/GraphQLParser.ApiTests/GraphQLParser.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,12 @@ namespace GraphQLParser.Visitors
public System.IO.TextWriter Writer { get; }
}
}
public enum SDLPrinterArgumentsMode
{
None = 0,
PreferNewLine = 1,
ForceNewLine = 2,
}
public static class SDLPrinterExtensions
{
public static string Print(this GraphQLParser.Visitors.SDLPrinter printer, GraphQLParser.AST.ASTNode node) { }
Expand All @@ -916,6 +922,7 @@ namespace GraphQLParser.Visitors
public class SDLPrinterOptions
{
public SDLPrinterOptions() { }
public GraphQLParser.Visitors.SDLPrinterArgumentsMode ArgumentsPrintMode { get; set; }
public bool EachDirectiveLocationOnNewLine { get; set; }
public bool EachUnionMemberOnNewLine { get; set; }
public int IndentSize { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQLParser.Benchmarks/GraphQLParser.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7</TargetFramework>
<TargetFramework>net8</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);1591;CA1822</NoWarn>
Expand All @@ -15,7 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\GraphQLParser\GraphQLParser.csproj" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.6" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
</ItemGroup>

</Project>
11 changes: 6 additions & 5 deletions src/GraphQLParser.Tests/GraphQLParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<SingleTestPlatform Condition="'$(SingleTestPlatform)' == ''">false</SingleTestPlatform>
<Nullable>disable</Nullable>
<NoWarn>$(NoWarn);1591;CA2012;IDE0008;IDE0022;IDE0058;IDE1006</NoWarn>
<NoWarn>$(NoWarn);1591;CA2012;CA1861;IDE0008;IDE0022;IDE0058;IDE1006</NoWarn>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

Expand All @@ -13,7 +13,8 @@
</PropertyGroup>

<PropertyGroup Condition="'$(SingleTestPlatform)' != 'true'">
<TargetFrameworks>netcoreapp3.1;net5;net6;net7</TargetFrameworks>
<TargetFrameworks>net6;net7;net8</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net462</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,10 +26,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 97d7207

Please sign in to comment.