diff --git a/src/commands/query.mjs b/src/commands/query.mjs index a25a28bf..e7d9803d 100644 --- a/src/commands/query.mjs +++ b/src/commands/query.mjs @@ -112,7 +112,10 @@ async function queryCommand(argv) { // If performance hints are enabled, print the summary to stderr. // This is only supported in v10. if ((summary || performanceHints) && apiVersion === "10") { - logger.stderr(formatQuerySummary(results.summary)); + const formattedSummary = formatQuerySummary(results.summary); + if (formattedSummary) { + logger.stderr(formattedSummary); + } } const output = formatQueryResponse(results, { diff --git a/src/commands/shell.mjs b/src/commands/shell.mjs index e225e539..e3c87e6c 100644 --- a/src/commands/shell.mjs +++ b/src/commands/shell.mjs @@ -188,7 +188,10 @@ async function buildCustomEval(argv) { }); if ((summary || performanceHints) && apiVersion === "10") { - logger.stdout(formatQuerySummary(res.summary)); + const formattedSummary = formatQuerySummary(res.summary); + if (formattedSummary) { + logger.stdout(formattedSummary); + } } } catch (err) { logger.stderr(formatError(err, { apiVersion, raw, color })); diff --git a/src/lib/command-helpers.mjs b/src/lib/command-helpers.mjs index 19e2eb8a..6689e817 100644 --- a/src/lib/command-helpers.mjs +++ b/src/lib/command-helpers.mjs @@ -158,14 +158,14 @@ const COMMON_CONFIGURABLE_QUERY_OPTIONS = { summary: { type: "boolean", description: - "Output the summary field of the API response. Only applies to v10 queries.", + "Output the summary field of the API response or nothing when it's empty. Only applies to v10 queries.", default: false, group: "API:", }, performanceHints: { type: "boolean", description: - "Output the performance hints for the current query. Only applies to v10 queries.", + "Output the performance hints for the current query or nothing when no hints are available. Only applies to v10 queries.", default: false, group: "API:", }, diff --git a/src/lib/fauna-client.mjs b/src/lib/fauna-client.mjs index 1d26dfd0..b2052484 100644 --- a/src/lib/fauna-client.mjs +++ b/src/lib/fauna-client.mjs @@ -138,7 +138,7 @@ export const formatQueryResponse = ( */ export const formatQuerySummary = (summary) => { if (!summary || typeof summary !== "string") { - return "No summary returned."; + return ""; } try { diff --git a/test/query.mjs b/test/query.mjs index 28b39d81..e306c2b6 100644 --- a/test/query.mjs +++ b/test/query.mjs @@ -375,6 +375,21 @@ describe("query", function () { ); expect(logger.stdout).to.have.been.calledWith(sinon.match(/fql/)); }); + + it("does not display anything if summary is empty", async function () { + runQueryFromString.resolves({ + summary: "", + data: "fql", + }); + + await run( + `query "Database.all()" --performanceHints --secret=foo`, + container, + ); + + expect(logger.stderr).to.not.be.called; + expect(logger.stdout).to.have.been.calledWith(sinon.match(/fql/)); + }); }); describe("v4", function () { diff --git a/test/shell.mjs b/test/shell.mjs index b8a82f5e..b3894a82 100644 --- a/test/shell.mjs +++ b/test/shell.mjs @@ -323,7 +323,8 @@ describe("shell", function () { it("can display performance hints", async function () { runQueryFromString.resolves({ - summary: "performance_hint: use a more efficient query\n", + summary: + "performance_hint: use a more efficient query\n1 | use a more efficient query", data: "fql", });