Skip to content

Commit

Permalink
Do not display a scary message if summary is empty (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecooper authored Dec 11, 2024
1 parent 5a5c028 commit a520215
Show file tree
Hide file tree
Showing 6 changed files with 28 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 @@ -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, {
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 @@ -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:",
},
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
15 changes: 15 additions & 0 deletions test/query.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
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 a520215

Please sign in to comment.