From cd1f48b920228a91948443572f49f7063eea41ce 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 } }