Skip to content

AST printer #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,26 @@ Json representation of the resulting AST would be:
}
}
```

## Printer
Accepts AST and converts it back into GraphQL query.
### Usage
```csharp
var lexer = new Lexer();
var parser = new Parser(lexer);
var printer = new Printer();

var ast = parser.Parse(new Source(@"
{
field
}"));

/*
Should result into:

{
field
}
*/
var query = printer.Print(ast);
```
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 3.0.0.{build}
version: 3.1.0.{build}
pull_requests:
do_not_increment_build_number: true
skip_tags: true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-parser",
"version": "3.0.0",
"version": "3.1.0",
"main": "index.js",
"repository": "[email protected]:graphql-dotnet/parser.git",
"author": "Joe McBride",
Expand Down
6 changes: 3 additions & 3 deletions src/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[assembly: AssemblyProduct("GraphQL Parser")]
[assembly: AssemblyCopyright("Copyright 2016-2017 Marek Magdziak et al. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("3.0.0")]
[assembly: AssemblyFileVersion("3.0.0")]
[assembly: AssemblyInformationalVersion("3.0.0")]
[assembly: AssemblyVersion("3.1.0")]
[assembly: AssemblyFileVersion("3.1.0")]
[assembly: AssemblyInformationalVersion("3.1.0")]
[assembly: CLSCompliant(false)]
29 changes: 29 additions & 0 deletions src/GraphQLParser.Tests/AssertExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace GraphQLParser.Tests
{
using KellermanSoftware.CompareNetObjects;
using System;

public static class AssertExtensions
{
public static void DeepEqual<T>(T obj1, T obj2, params Type[] typesToIgnore)
{
var compareLogic = new CompareLogic();

if (typesToIgnore != null)
{
foreach (var type in typesToIgnore)
{
compareLogic.Config.TypesToIgnore.Add(type);
}
}

var result = compareLogic.Compare(obj1, obj2);

if (!result.AreEqual)
throw new Exception(
"Objects are not the same: " +
Environment.NewLine + Environment.NewLine +
result.DifferencesString);
}
}
}
1 change: 1 addition & 0 deletions src/GraphQLParser.Tests/GraphQLParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CompareNETObjects" Version="4.55.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQLParser.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private static ASTNode GetSingleSelection(GraphQLDocument document)
return GetSingleOperationDefinition(document).SelectionSet.Selections.Single();
}

private static string LoadKitchenSink()
public static string LoadKitchenSink()
{
return @"# Copyright (c) 2015, Facebook, Inc.
# All rights reserved.
Expand Down
32 changes: 32 additions & 0 deletions src/GraphQLParser.Tests/PrinterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace GraphQLParser.Tests
{
using GraphQLParser.AST;
using Xunit;

public class PrinterTests
{
private Printer printer;

public PrinterTests()
{
this.printer = new Printer();
}

[Fact]
public void Print_KitchenSink_DoesNotModifyAST()
{
var ast = this.Parse(ParserTests.LoadKitchenSink());
var printed = this.printer.Print(ast);
var ast2 = this.Parse(printed);

AssertExtensions.DeepEqual(ast, ast2, typeof(GraphQLLocation));
}

private GraphQLDocument Parse(string body)
{
var parser = new Parser(new Lexer());

return parser.Parse(new Source(body));
}
}
}
2 changes: 1 addition & 1 deletion src/GraphQLParser/GraphQLParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Library containing lexer and parser for GraphQL syntax</Description>
<AssemblyTitle>GraphQL Parser for .NET</AssemblyTitle>
<VersionPrefix>3.0.0</VersionPrefix>
<VersionPrefix>3.1.0</VersionPrefix>
<Authors>Marek Magdziak</Authors>
<TargetFrameworks>net45;netstandard1.1</TargetFrameworks>
<NoWarn>$(NoWarn);1591</NoWarn>
Expand Down
Loading