Skip to content

Commit

Permalink
Fixed pagination projection with alias (#3627)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored May 6, 2021
1 parent 8836a90 commit a6e45fb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ private Selection CreateCombinedSelection(

private (string filedName, IObjectField field) TryGetObjectField(IPageType type)
{
if (type.Fields.ContainsField("nodes"))
if (type.Fields.FirstOrDefault(x => x.Name.Value == "nodes") is { } nodes)
{
return ("nodes", type.Fields["nodes"]);
return ("nodes", nodes);
}

if (type.Fields.ContainsField("items"))
if (type.Fields.FirstOrDefault(x => x.Name.Value == "items") is { } items)
{
return ("items", type.Fields["items"]);
return ("items", items);
}

throw new GraphQLException(
Expand All @@ -95,7 +95,8 @@ private static void CollectSelectionOfEdges(
SelectionOptimizerContext context,
List<ISelectionNode> selections)
{
if (context.Fields.TryGetValue("edges", out Selection? edgeSelection))
if (context.Fields.Values
.FirstOrDefault(x => x.Field.Name == "edges") is { } edgeSelection)
{
foreach (var edgeSubField in edgeSelection.SelectionSet.Selections)
{
Expand All @@ -117,7 +118,8 @@ private static void CollectSelectionOfItems(
SelectionOptimizerContext context,
List<ISelectionNode> selections)
{
if (context.Fields.TryGetValue("items", out Selection? itemSelection))
if (context.Fields.Values
.FirstOrDefault(x => x.Field.Name == "items") is { } itemSelection)
{
foreach (var nodeField in itemSelection.SelectionSet.Selections)
{
Expand All @@ -130,7 +132,8 @@ private static void CollectSelectionOfNodes(
SelectionOptimizerContext context,
List<ISelectionNode> selections)
{
if (context.Fields.TryGetValue("nodes", out Selection? nodeSelection))
if (context.Fields.Values
.FirstOrDefault(x => x.Field.Name == "nodes") is { } nodeSelection)
{
foreach (var nodeField in nodeSelection.SelectionSet.Selections)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,24 @@ public async Task CreateOffsetPaging_Projection_Should_Stop_When_UsePagingEncoun
res1.MatchSqlSnapshot();
}

[Fact]
public async Task CreateNullable_NodesAndEdgesWithAliases()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooNullableEntities,
usePaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root{ b: nodes{ baz } a: edges { node { bar }} }}")
.Create());

res1.MatchSqlSnapshot();
}

public class Foo
{
public int Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"data": {
"root": {
"b": [
{
"baz": "a"
},
{
"baz": null
},
{
"baz": "c"
}
],
"a": [
{
"node": {
"bar": true
}
},
{
"node": {
"bar": null
}
},
{
"node": {
"bar": false
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT "d"."Baz", "d"."Bar"
FROM "Data" AS "d"

0 comments on commit a6e45fb

Please sign in to comment.