UNPKG

firebase-tools

Version:
32 lines (31 loc) • 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.graphqlResponseToToolResponse = graphqlResponseToToolResponse; exports.parseVariables = parseVariables; const types_1 = require("../../../dataconnect/types"); const util_1 = require("../../util"); function graphqlResponseToToolResponse(g) { if ((0, types_1.isGraphQLResponse)(g)) { const isError = g.errors?.length > 0; const contentString = `${isError ? "A GraphQL error occurred while executing the operation:" : ""}${JSON.stringify(g, null, 2)}`; return { isError, content: [{ type: "text", text: contentString }], }; } else { return (0, util_1.mcpError)(JSON.stringify(g, null, 2)); } } function parseVariables(unparsedVariables) { let obj; try { obj = JSON.parse(unparsedVariables || "{}"); } catch (e) { throw new Error(`Provided variables string \`${String(unparsedVariables)}\` is not valid JSON.`); } if (typeof obj !== "object" || obj == null) throw new Error("not an object"); return obj; }