Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"test":
test:
- src/GraphQLParser.ApiTests/**/*
- src/GraphQLParser.Tests/**/*

"CI":
CI:
- .github/workflows/**/*

"code style":
code style:
- .editorconfig

"documentation":
documentation:
- README.md

"performance":
performance:
- src/GraphQLParser.Benchmarks/**/*
4 changes: 3 additions & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v2
- uses: actions/labeler@v3
with:
sync-labels: ""
repo-token: "${{ secrets.GITHUB_TOKEN }}"
continue-on-error: true
18 changes: 18 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,21 @@ jobs:
- name: Publish Nuget packages to Nuget registry
working-directory: src
run: dotnet nuget push "out/*" -k ${{secrets.NUGET_AUTH_TOKEN}}
- name: Upload Nuget packages as release artifacts
uses: actions/github-script@v2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
for (let file of await fs.readdir('src/out')) {
console.log('uploading', file);
await github.repos.uploadReleaseAsset({
owner,
repo,
release_id: ${{ github.event.release.id }},
name: file,
data: await fs.readFile(`src/out/${file}`)
});
}
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<VersionPrefix>5.3.4-preview</VersionPrefix>
<VersionPrefix>6.0.0-preview</VersionPrefix>
<LangVersion>latest</LangVersion>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -18,6 +18,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables -->
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<NoWarn>$(NoWarn);1591</NoWarn>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ namespace GraphQLParser
}
public interface ISource
{
string Body { get; set; }
string Name { get; set; }
string Body { get; }
string Name { get; }
}
public class Lexer : GraphQLParser.ILexer
{
Expand All @@ -403,6 +403,7 @@ namespace GraphQLParser
public readonly struct Location
{
public Location(GraphQLParser.ISource source, int position) { }
public Location(string source, int position) { }
public int Column { get; }
public int Line { get; }
}
Expand All @@ -423,8 +424,8 @@ namespace GraphQLParser
{
public Source(string body) { }
public Source(string body, string name) { }
public string Body { get; set; }
public string Name { get; set; }
public string Body { get; }
public string Name { get; }
}
public readonly struct Token
{
Expand Down
1 change: 0 additions & 1 deletion src/GraphQLParser.Tests/LexerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Shouldly;
using Xunit;

Expand Down
1 change: 0 additions & 1 deletion src/GraphQLParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
..\LICENSE.md = ..\LICENSE.md
..\assets\logo.64x64.png = ..\assets\logo.64x64.png
NuGet.config = NuGet.config
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down
4 changes: 1 addition & 3 deletions src/GraphQLParser/AST/GraphQLLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ public GraphQLLocation(int start, int end)
/// </summary>
public int End { get; }



public bool Equals(GraphQLLocation other) => Start == other.Start && End == other.End;

public override bool Equals(object obj) => obj is GraphQLLocation l ? Equals(l) : false;
public override bool Equals(object obj) => obj is GraphQLLocation l && Equals(l);

public override int GetHashCode() => (Start, End).GetHashCode();

Expand Down
8 changes: 4 additions & 4 deletions src/GraphQLParser/ISource.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace GraphQLParser
namespace GraphQLParser
{
public interface ISource
{
string Body { get; set; }
string Body { get; }

string Name { get; set; }
string Name { get; }
}
}
}
21 changes: 15 additions & 6 deletions src/GraphQLParser/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@ public readonly struct Location
private static readonly Regex _lineRegex = new Regex("\r\n|[\n\r]", RegexOptions.ECMAScript);

public Location(ISource source, int position)
: this(source.Body, position)
{

}

public Location(string source, int position)
{
Line = 1;
Column = position + 1;

var matches = _lineRegex.Matches(source.Body);
foreach (Match match in matches)
if (position > 0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimization for position=0 (uninitialized location from graphql-dotnet/graphql-dotnet#2111 (comment))

{
if (match.Index >= position)
break;
var matches = _lineRegex.Matches(source);
foreach (Match match in matches)
{
if (match.Index >= position)
break;

Line++;
Column = position + 1 - (match.Index + matches[0].Length);
Line++;
Column = position + 1 - (match.Index + matches[0].Length);
}
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/GraphQLParser/ParserContext.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GraphQLParser.AST;
using GraphQLParser.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using GraphQLParser.AST;
using GraphQLParser.Exceptions;

namespace GraphQLParser
{
Expand Down Expand Up @@ -529,7 +528,7 @@ private GraphQLFieldSelection ParseFieldSelection()
return CreateFieldSelection(start, name, alias, comment);
}

private GraphQLValue ParseFloat(bool isConstant)
private GraphQLValue ParseFloat(/*bool isConstant*/)
{
var token = _currentToken;
Advance();
Expand Down Expand Up @@ -631,7 +630,7 @@ private GraphQLInputValueDefinition ParseInputValueDef()
};
}

private GraphQLValue ParseInt(bool isConstant)
private GraphQLValue ParseInt(/*bool isConstant*/)
{
var token = _currentToken;
Advance();
Expand Down Expand Up @@ -719,7 +718,7 @@ private GraphQLNamedType ParseNamedType()
};
}

private GraphQLValue ParseNameValue(bool isConstant)
private GraphQLValue ParseNameValue(/*bool isConstant*/)
{
var token = _currentToken;

Expand Down Expand Up @@ -891,7 +890,7 @@ private GraphQLSelectionSet ParseSelectionSet()
};
}

private GraphQLValue ParseString(bool isConstant)
private GraphQLValue ParseString(/*bool isConstant*/)
{
var token = _currentToken;
Advance();
Expand Down Expand Up @@ -987,10 +986,10 @@ private GraphQLUnionTypeDefinition ParseUnionTypeDefinition()
{
TokenKind.BRACKET_L => ParseList(isConstant),
TokenKind.BRACE_L => ParseObject(isConstant),
TokenKind.INT => ParseInt(isConstant),
TokenKind.FLOAT => ParseFloat(isConstant),
TokenKind.STRING => ParseString(isConstant),
TokenKind.NAME => ParseNameValue(isConstant),
TokenKind.INT => ParseInt(/*isConstant*/),
TokenKind.FLOAT => ParseFloat(/*isConstant*/),
TokenKind.STRING => ParseString(/*isConstant*/),
TokenKind.NAME => ParseNameValue(/*isConstant*/),
TokenKind.DOLLAR when !isConstant => ParseVariable(),
_ => throw new GraphQLSyntaxErrorException($"Unexpected {_currentToken}", _source, _currentToken.Start)
};
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQLParser/Source.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public Source(string body, string name)
Body = body ?? string.Empty;
}

public string Body { get; set; }
public string Body { get; }

public string Name { get; set; }
public string Name { get; }
}
}