Skip to content

Commit

Permalink
Do not display a scary message if summary is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ecooper committed Dec 11, 2024
1 parent b3b82eb commit 5901b9e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/commands/query.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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, {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
4 changes: 2 additions & 2 deletions src/lib/command-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,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 its 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:",
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fauna-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const formatQueryResponse = (
*/
export const formatQuerySummary = (summary) => {
if (!summary || typeof summary !== "string") {
return "No summary returned.";
return "";
}

try {
Expand Down
3 changes: 2 additions & 1 deletion test/shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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<diagnostics>",
summary:
"performance_hint: use a more efficient query\n1 | use a more efficient query",
data: "fql",
});

Expand Down

0 comments on commit 5901b9e

Please sign in to comment.