From 06ca29b1525a48c028b08a85ed3db4a2b6b53587 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 16 Jan 2023 15:57:14 +0100 Subject: [PATCH 1/5] Add test querying only totalCount --- test/tests/queries/totalCount.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/tests/queries/totalCount.test.js b/test/tests/queries/totalCount.test.js index acb6df73..92d8d0bc 100644 --- a/test/tests/queries/totalCount.test.js +++ b/test/tests/queries/totalCount.test.js @@ -37,6 +37,27 @@ describe('graphql - queries with totalCount', () => { expect(response.data).toEqual({ data }) }) + test('query selecting only totalCount', async () => { + const query = `#graphql + { + AdminService { + Books { + totalCount + } + } + } + ` + const data = { + AdminService: { + Books: { + totalCount: 5 + } + } + } + const response = await POST('/graphql', { query }) + expect(response.data).toEqual({ data }) + }) + test('query with totalCount and simple filter', async () => { const query = `#graphql { From 8bbd16899f788ca5ee27280a7016aaf7281223e2 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 16 Jan 2023 16:07:53 +0100 Subject: [PATCH 2/5] Check if is connection from selected field names --- lib/resolvers/parse/util/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/resolvers/parse/util/index.js b/lib/resolvers/parse/util/index.js index 645e78ad..6eaa608f 100644 --- a/lib/resolvers/parse/util/index.js +++ b/lib/resolvers/parse/util/index.js @@ -16,9 +16,9 @@ const _filterOutDuplicateColumnsSelections = selections => { } const getPotentiallyNestedNodesSelections = selections => { - const nodesSelections = selections.filter(selection => selection.name.value === CONNECTION_FIELDS.nodes) - if (nodesSelections.length === 0) return selections - return _filterOutDuplicateColumnsSelections(selections) + const isConnection = selections.some(selection => Object.values(CONNECTION_FIELDS).includes(selection.name.value)) + if (isConnection) return _filterOutDuplicateColumnsSelections(selections) + return selections } module.exports = { getPotentiallyNestedNodesSelections } From 0cdfbec5c7d6206a4d3b19ab5ff4a890bc92837d Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 16 Jan 2023 17:15:49 +0100 Subject: [PATCH 3/5] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffbcf3c8..8ee66484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed a server crash that occourred if an entity property is named `localized`. +- A bug where the field `totalCount` could not be queried on its own ### Removed From 7a1675dec2d3b76102617c50e78ba914a006dec8 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Thu, 19 Jan 2023 17:51:01 +0100 Subject: [PATCH 4/5] Use gql tag in test --- test/tests/queries/totalCount.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/queries/totalCount.test.js b/test/tests/queries/totalCount.test.js index e8fc1fcc..dc4fd946 100644 --- a/test/tests/queries/totalCount.test.js +++ b/test/tests/queries/totalCount.test.js @@ -39,7 +39,7 @@ describe('graphql - queries with totalCount', () => { }) test('query selecting only totalCount', async () => { - const query = `#graphql + const query = gql` { AdminService { Books { From e8efc2b13a8f6ed71d725e558d7cba9b5c19ada5 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 23 Jan 2023 18:11:19 +0100 Subject: [PATCH 5/5] Use ternary conditional operator --- lib/resolvers/parse/util/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/resolvers/parse/util/index.js b/lib/resolvers/parse/util/index.js index 6eaa608f..878676f1 100644 --- a/lib/resolvers/parse/util/index.js +++ b/lib/resolvers/parse/util/index.js @@ -17,8 +17,7 @@ const _filterOutDuplicateColumnsSelections = selections => { const getPotentiallyNestedNodesSelections = selections => { const isConnection = selections.some(selection => Object.values(CONNECTION_FIELDS).includes(selection.name.value)) - if (isConnection) return _filterOutDuplicateColumnsSelections(selections) - return selections + return isConnection ? _filterOutDuplicateColumnsSelections(selections) : selections } module.exports = { getPotentiallyNestedNodesSelections }