Skip to content

Commit

Permalink
Merge from v8
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Dec 11, 2023
2 parents 67e2834 + aa5475e commit b201d09
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET SDK
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/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup .NET SDK
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
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup .NET SDK
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 Down
7 changes: 2 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.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 @@ -73,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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,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 @@ -36,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 @@ -95,7 +95,8 @@ new SDLPrinter().Print(document, sb);

// print to a string with some options
var sdlPrinter = new SDLPrinter(
new SDLPrinterOptions {
new SDLPrinterOptions
{
PrintComments = true,
EachDirectiveLocationOnNewLine = true,
EachUnionMemberOnNewLine = true,
Expand All @@ -122,8 +123,8 @@ query {
### 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
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.

Expand Down
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
6 changes: 3 additions & 3 deletions src/GraphQLParser.ApiTests/GraphQLParser.ApiTests.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>
<NoWarn>$(NoWarn);1591</NoWarn>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -10,8 +10,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5" />
<PackageReference Include="PublicApiGenerator" Version="11.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
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 Down
8 changes: 4 additions & 4 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,7 @@
</PropertyGroup>

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

Expand All @@ -28,8 +28,8 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.5.3" />
<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
16 changes: 8 additions & 8 deletions src/GraphQLParser.Tests/NodeHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public void NodeHelper_Should_Return_Proper_Nodes_1()
foreach (var method in typeof(NodeHelper).GetMethods().Where(m => m.IsStatic))
{
var node = method.GetParameters().Length == 1
? (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.None })
: (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.None, Activator.CreateInstance(method.GetParameters()[1].ParameterType) });
? (ASTNode)method.Invoke(null, [IgnoreOptions.None])
: (ASTNode)method.Invoke(null, [IgnoreOptions.None, Activator.CreateInstance(method.GetParameters()[1].ParameterType)]);

node.Comments = new List<GraphQLComment> { new GraphQLComment("abcdef") };
if (node is not GraphQLComment &&
Expand All @@ -29,8 +29,8 @@ public void NodeHelper_Should_Return_Proper_Nodes_2()
foreach (var method in typeof(NodeHelper).GetMethods().Where(m => m.IsStatic))
{
var node = method.GetParameters().Length == 1
? (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.Comments })
: (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.Comments, Activator.CreateInstance(method.GetParameters()[1].ParameterType) });
? (ASTNode)method.Invoke(null, [IgnoreOptions.Comments])
: (ASTNode)method.Invoke(null, [IgnoreOptions.Comments, Activator.CreateInstance(method.GetParameters()[1].ParameterType)]);

node.Comments = new List<GraphQLComment> { new GraphQLComment("abcdef") };
node.Comment.ShouldBeNull();
Expand All @@ -46,8 +46,8 @@ public void NodeHelper_Should_Return_Proper_Nodes_3()
foreach (var method in typeof(NodeHelper).GetMethods().Where(m => m.IsStatic))
{
var node = method.GetParameters().Length == 1
? (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.Locations })
: (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.Locations, Activator.CreateInstance(method.GetParameters()[1].ParameterType) });
? (ASTNode)method.Invoke(null, [IgnoreOptions.Locations])
: (ASTNode)method.Invoke(null, [IgnoreOptions.Locations, Activator.CreateInstance(method.GetParameters()[1].ParameterType)]);

node.Comments = new List<GraphQLComment> { new GraphQLComment("abcdef") };
if (node is not GraphQLComment &&
Expand All @@ -67,8 +67,8 @@ public void NodeHelper_Should_Return_Proper_Nodes_4()
foreach (var method in typeof(NodeHelper).GetMethods().Where(m => m.IsStatic))
{
var node = method.GetParameters().Length == 1
? (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.All })
: (ASTNode)method.Invoke(null, new object[] { IgnoreOptions.All, Activator.CreateInstance(method.GetParameters()[1].ParameterType) });
? (ASTNode)method.Invoke(null, [IgnoreOptions.All])
: (ASTNode)method.Invoke(null, [IgnoreOptions.All, Activator.CreateInstance(method.GetParameters()[1].ParameterType)]);

node.Comments = new List<GraphQLComment> { new GraphQLComment("abcdef") };
node.Comment.ShouldBeNull();
Expand Down
24 changes: 12 additions & 12 deletions src/GraphQLParser.Tests/Visitors/SDLPrinterFromManualASTTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class SDLPrinterFromManualASTTests
public async Task SelectionSet_Without_Parent_Should_Be_Printed_On_New_Line()
{
var selectionSet = new GraphQLSelectionSetWithComment { Selections = new List<ASTNode>() };
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter(new SDLPrinterOptions { PrintComments = true });
await printer.PrintAsync(selectionSet, writer);
writer.ToString().ShouldBe(@"{
}");
selectionSet.Comments = new List<GraphQLComment> { new GraphQLComment("comment") };
writer = new StringWriter();
await printer.PrintAsync(selectionSet, writer);
writer.ToString().ShouldBe(@"#comment
using var writer2 = new StringWriter();
await printer.PrintAsync(selectionSet, writer2);
writer2.ToString().ShouldBe(@"#comment
{
}");
}
Expand All @@ -28,15 +28,15 @@ public async Task SelectionSet_Under_Operation_With_Null_Name_Should_Be_Printed_
{
SelectionSet = new GraphQLSelectionSetWithComment { Selections = new List<ASTNode>() }
};
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter(new SDLPrinterOptions { PrintComments = true });
await printer.PrintAsync(def, writer);
writer.ToString().ShouldBe(@"{
}");
def.SelectionSet.Comments = new List<GraphQLComment> { new GraphQLComment("comment") };
writer = new StringWriter();
await printer.PrintAsync(def, writer);
writer.ToString().ShouldBe(@"#comment
using var writer2 = new StringWriter();
await printer.PrintAsync(def, writer2);
writer2.ToString().ShouldBe(@"#comment
{
}");
}
Expand All @@ -55,7 +55,7 @@ public async Task SelectionSet_Under_Operation_With_Null_Name_Should_Be_Printed_
public async Task Description_Without_Parent_Should_Be_Printed(string text, string expected)
{
var description = new GraphQLDescription(text);
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(description, writer);
writer.ToString().ShouldBe(expected);
Expand All @@ -79,7 +79,7 @@ Line 4
public async Task Description_With_Escaped_Unicode_Should_Be_Printed(string text, string expected)
{
var description = new GraphQLDescription(text);
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(description, writer);
writer.ToString().ShouldBe(expected);
Expand All @@ -95,7 +95,7 @@ public async Task InputValueDefinition_Without_Parent_Should_Be_Printed()
DefaultValue = new GraphQLStringValue("abc")
};

var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(def, writer);
writer.ToString().ShouldBe("field: String = \"abc\"");
Expand All @@ -105,7 +105,7 @@ public async Task InputValueDefinition_Without_Parent_Should_Be_Printed()
public async Task Directive_Without_Parent_Should_Be_Printed()
{
var directive = new GraphQLDirective { Name = new GraphQLName("upper") };
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(directive, writer);
writer.ToString().ShouldBe("@upper");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public async Task Print_Matches_PrintAsync_String()
{
var query = "KitchenSink".ReadGraphQLFile().Parse();
var writer = new SDLPrinter();
var sw = new StringWriter();
using var sw = new StringWriter();
await writer.PrintAsync(query, sw);
sw.Flush();
var txt = sw.ToString();
Expand Down Expand Up @@ -941,7 +941,7 @@ public async Task SDLPrinter_Should_Print_Document(
IndentSize = indentSize,
ArgumentsPrintMode = mode,
});
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer);
Expand Down Expand Up @@ -997,7 +997,7 @@ public async Task SDLPrinter_Should_Print_BlockStrings(int number, string input,
? "\"\"\"" + expected + "\"\"\""
: "\"" + expected + "\"";

var writer = new StringWriter();
using var writer = new StringWriter();

var document = (input + " scalar a").Parse();

Expand Down Expand Up @@ -1028,7 +1028,7 @@ public async Task SDLPrinter_Should_Print_EscapedStrings(string stringValue)
string expected = @$"{{
a(p: {stringValue})
}}";
var writer = new StringWriter();
using var writer = new StringWriter();

var document = query.Parse();

Expand Down Expand Up @@ -1076,7 +1076,7 @@ public void OperationPrints(string input, string expected)
[InlineData("directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT")]
public async Task SDLPrinter_Should_Throw_On_Unknown_Values(string text)
{
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await new DoBadThingsVisitor().VisitAsync(document, new Context());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task Printer_Should_Print_Pretty_If_Directives_Skipped(
string expected)
{
var printer = new MyPrinter();
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public async Task Printer_Should_Print_Pretty_If_Definitions_Skipped(
string expected)
{
var printer = new PrintOnlyStartsWithA();
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer);
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQLParser.Tests/Visitors/StructurePrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ Name [dir]
")]
public async Task StructurePrinter_Should_Print_Tree(string text, string expected)
{
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();
await _structPrinter1.PrintAsync(document, writer);
var actual = writer.ToString();
Expand All @@ -302,7 +302,7 @@ public async Task StructurePrinter_Should_Print_Tree(string text, string expecte
")]
public async Task StructurePrinter_Should_Print_Tree_Without_Names(string text, string expected)
{
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();
await _structPrinter2.PrintAsync(document, writer);
var actual = writer.ToString();
Expand Down Expand Up @@ -547,7 +547,7 @@ public async Task StructurePrinter_Should_Print_Tree_With_Locations(string text,
if (option == IgnoreOptions.Comments && !ignoreComments)
continue;

var writer = new StringWriter();
using var writer = new StringWriter();

var document = text.Parse(new ParserOptions { Ignore = option });
await _structPrinter3.PrintAsync(document, writer);
Expand Down
Loading

0 comments on commit b201d09

Please sign in to comment.