From dcb334b56428f1d157f2aa2b6edbea089b7693af Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 13 Oct 2021 13:22:13 +0100 Subject: [PATCH] Fixing some issues found with query while testing. --- packages/server/src/api/controllers/query.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/server/src/api/controllers/query.js b/packages/server/src/api/controllers/query.js index aea8d13b52..89bf1a8ab0 100644 --- a/packages/server/src/api/controllers/query.js +++ b/packages/server/src/api/controllers/query.js @@ -29,9 +29,6 @@ function formatResponse(resp) { resp = { response: resp } } } - if (!Array.isArray(resp)) { - resp = [resp] - } return resp } @@ -49,15 +46,19 @@ async function runAndTransform( rows = runner.execute() } - // get all the potential fields in the schema - let keys = rows.flatMap(Object.keys) + // needs to an array for next step + if (!Array.isArray(rows)) { + rows = [rows] + } // map into JSON if just raw primitive here - if (keys.length === 0) { + if (rows.find(row => typeof row !== "object")) { rows = rows.map(value => ({ value })) - keys = ["value"] } + // get all the potential fields in the schema + let keys = rows.flatMap(Object.keys) + return { rows, keys } }