From 221dd91a1ff72741e20603e97dbaa999eecc87d6 Mon Sep 17 00:00:00 2001 From: Tomi Tuhkanen Date: Sun, 30 Sep 2018 10:01:27 +0300 Subject: [PATCH] Do not return empty arrays with GraphQL filter --- CHANGELOG.md | 1 + FakeServer.Test/GraphQLTests.cs | 2 ++ FakeServer/GraphQL/GraphQL.cs | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 461bb02..d15cbae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fix for HEAD method use and ETag to support HEAD method * .NET Core version to 2.1 * Support for objects +* Do not return empty arrays with GraphQL filter ### [0.6.0] - 2017-11-30 * Caching of unchanged resources with ETag and If-None-Match headers diff --git a/FakeServer.Test/GraphQLTests.cs b/FakeServer.Test/GraphQLTests.cs index 53ec2ea..bcd6bee 100644 --- a/FakeServer.Test/GraphQLTests.cs +++ b/FakeServer.Test/GraphQLTests.cs @@ -33,6 +33,8 @@ public void Query_Families() Assert.NotEmpty(js); + Assert.Equal(4, results.Data["families"].Count); + UTHelpers.Down(filePath); } diff --git a/FakeServer/GraphQL/GraphQL.cs b/FakeServer/GraphQL/GraphQL.cs index 006268b..6ab14e1 100644 --- a/FakeServer/GraphQL/GraphQL.cs +++ b/FakeServer/GraphQL/GraphQL.cs @@ -284,7 +284,7 @@ private static ExecutionResult ResolveField(dynamic source, dynamic target, Fiel var r = ResolveField(item, rootObject, i.Value); rootObject = r.Data; } - + if (rootObject != null) result.Add(rootObject); } @@ -332,6 +332,9 @@ private static ExecutionResult ResolveField(dynamic source, dynamic target, Fiel if (rootObject != null) newArray.Add(rootObject); } + + if (f.Arguments.Any() && newArray.Count == 0) + target = null; } else {