Skip to content

Commit

Permalink
[WIP] File System persisted queries (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
willwolfram18 authored and michaelstaib committed Aug 5, 2019
1 parent 8f3baf2 commit 1bf148d
Show file tree
Hide file tree
Showing 116 changed files with 3,570 additions and 267 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added new syntax visitor API.
- Added Redis subscription provider [#902](https://github.com/ChilliCream/hotchocolate/pull/902)
- Added support for batching over HTTP [#933](https://github.com/ChilliCream/hotchocolate/pull/933)
- Added support for persisted queries and added a middleware to enable the active persisted query flow. [#858](https://github.com/ChilliCream/hotchocolate/pull/858)

### Changed

Expand Down
46 changes: 45 additions & 1 deletion src/Core/Abstractions.Tests/Execution/QueryDocumentTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.IO;
using System;
using HotChocolate.Language;
using Snapshooter.Xunit;
using Xunit;
using System.Threading.Tasks;

namespace HotChocolate.Execution.Tests
{
Expand Down Expand Up @@ -55,7 +57,49 @@ public void QueryDocument_ToSource()

// assert
QuerySyntaxSerializer.Serialize(
Utf8GraphQLParser.Parse(query.ToSource()))
Utf8GraphQLParser.Parse(query.ToSpan()))
.ToString().MatchSnapshot();
}

[Fact]
public async Task QueryDocument_WriteToAsync()
{
// arrange
DocumentNode document = Utf8GraphQLParser.Parse("{ a }");
var query = new QueryDocument(document);
byte[] buffer;

// act
using (var stream = new MemoryStream())
{
await query.WriteToAsync(stream);
buffer = stream.ToArray();
}

// assert
QuerySyntaxSerializer.Serialize(
Utf8GraphQLParser.Parse(buffer))
.ToString().MatchSnapshot();
}

[Fact]
public void QueryDocument_WriteTo()
{
// arrange
DocumentNode document = Utf8GraphQLParser.Parse("{ a }");
var query = new QueryDocument(document);
byte[] buffer;

// act
using (var stream = new MemoryStream())
{
query.WriteTo(stream);
buffer = stream.ToArray();
}

// assert
QuerySyntaxSerializer.Serialize(
Utf8GraphQLParser.Parse(buffer))
.ToString().MatchSnapshot();
}
}
Expand Down
183 changes: 183 additions & 0 deletions src/Core/Abstractions.Tests/Execution/QueryRequestBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,188 @@ public void BuildRequest_QueryAndTryAddVariable_VariableIsNotSet()
// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndTryAddExtension_ExtensionIsSet()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.TryAddExtension("one", "bar")
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndTryAddExtension_ExtensionIsNotSet()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.TryAddExtension("one", "bar")
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndAddExtension_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.AddExtension("two", "bar")
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetExtensions_RequestIsCreated_1()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.AddExtension("two", "bar")
.SetExtensions(new Dictionary<string, object>
{
{ "three", "baz" }
})
.Create();

// assert
// only three should exist
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetExtensions_RequestIsCreated_2()
{
// arrange
IReadOnlyDictionary<string, object> ext =
new Dictionary<string, object>
{
{ "three", "baz" }
};

// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.AddExtension("two", "bar")
.SetExtensions(ext)
.Create();

// assert
// only three should exist
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetExtensions_RequestIsCreated_3()
{
// arrange
IReadOnlyDictionary<string, object> ext =
new Dictionary<string, object>
{
{ "three", "baz" }
};

// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.AddExtension("two", "bar")
.SetExtensions(ext)
.AddExtension("four", "bar")
.Create();

// assert
// only three should exist
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetExtensions_RequestIsCreated_4()
{
// arrange
IDictionary<string, object> ext =
new Dictionary<string, object>
{
{ "three", "baz" }
};

// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.AddExtension("two", "bar")
.SetExtensions(ext)
.Create();

// assert
// only three should exist
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetExtensions_RequestIsCreated_5()
{
// arrange
IDictionary<string, object> ext =
new Dictionary<string, object>
{
{ "three", "baz" }
};

// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.AddExtension("two", "bar")
.SetExtensions(ext)
.AddExtension("four", "bar")
.Create();

// assert
// only three should exist
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetExtension_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddExtension("one", "foo")
.SetExtension("one", "bar")
.Create();

// assert
// one should be bar
request.MatchSnapshot();
}
}
}
46 changes: 45 additions & 1 deletion src/Core/Abstractions.Tests/Execution/QuerySourceTextTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Threading.Tasks;
using HotChocolate.Language;
using Snapshooter.Xunit;
using Xunit;
Expand Down Expand Up @@ -49,7 +51,49 @@ public void QueryDocument_ToSource()

// assert
QuerySyntaxSerializer.Serialize(
Utf8GraphQLParser.Parse(query.ToSource()))
Utf8GraphQLParser.Parse(query.ToSpan()))
.ToString().MatchSnapshot();
}

[Fact]
public async Task QuerySourceText_WriteToAsync()
{
// arrange
DocumentNode document = Utf8GraphQLParser.Parse("{ a }");
var query = new QuerySourceText("{ a }");
byte[] buffer;

// act
using (var stream = new MemoryStream())
{
await query.WriteToAsync(stream);
buffer = stream.ToArray();
}

// assert
QuerySyntaxSerializer.Serialize(
Utf8GraphQLParser.Parse(buffer))
.ToString().MatchSnapshot();
}

[Fact]
public void QuerySourceText_WriteTo()
{
// arrange
DocumentNode document = Utf8GraphQLParser.Parse("{ a }");
var query = new QuerySourceText("{ a }");
byte[] buffer;

// act
using (var stream = new MemoryStream())
{
query.WriteTo(stream);
buffer = stream.ToArray();
}

// assert
QuerySyntaxSerializer.Serialize(
Utf8GraphQLParser.Parse(buffer))
.ToString().MatchSnapshot();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
a
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
a
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@
"QueryName": null,
"QueryHash": null,
"OperationName": null,
"VariableValues": null,
"VariableValues": {},
"InitialValue": null,
"Properties": null,
"Services": null
"Properties": {},
"Services": null,
"Extensions": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"QueryName": null,
"QueryHash": null,
"OperationName": null,
"VariableValues": null,
"VariableValues": {},
"InitialValue": null,
"Properties": null,
"Services": null
"Properties": {},
"Services": null,
"Extensions": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Query": {
"Text": "{ foo }"
},
"QueryName": null,
"QueryHash": null,
"OperationName": null,
"VariableValues": {},
"InitialValue": null,
"Properties": {},
"Services": null,
"Extensions": {
"one": "foo",
"two": "bar"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"QueryName": null,
"QueryHash": null,
"OperationName": null,
"VariableValues": null,
"VariableValues": {},
"InitialValue": null,
"Properties": {
"one": "foo",
"two": "bar"
},
"Services": null
"Services": null,
"Extensions": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"two": "bar"
},
"InitialValue": null,
"Properties": null,
"Services": null
"Properties": {},
"Services": null,
"Extensions": {}
}
Loading

0 comments on commit 1bf148d

Please sign in to comment.