graphql-yoga
Version:
<div align="center"><img src="./website/public/cover.png" width="720" /></div>
33 lines (32 loc) • 1.28 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonStringifyResult = void 0;
const error_js_1 = require("../../error.js");
// JSON stringifier that adjusts the result error extensions while serialising
function jsonStringifyResult(result) {
return JSON.stringify(Array.isArray(result)
? result.map(omitInternalsFromResultErrors)
: omitInternalsFromResultErrors(result));
}
exports.jsonStringifyResult = jsonStringifyResult;
function omitInternalsFromResultErrors(result) {
return {
...result,
errors: result.errors?.map(omitInternalsFromError),
};
}
function omitInternalsFromError(err) {
if ((0, error_js_1.isGraphQLError)(err)) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TS should check for unused vars instead
const { http, unexpected, ...extensions } = err.extensions;
return (0, error_js_1.createGraphQLError)(err.message, {
nodes: err.nodes,
source: err.source,
positions: err.positions,
path: err.path,
originalError: omitInternalsFromError(err.originalError),
extensions: Object.keys(extensions).length ? extensions : undefined,
});
}
return err;
}
;