graphql-yoga
Version:
<div align="center"><img src="./website/public/cover.png" width="720" /></div>
29 lines (28 loc) • 1.11 kB
JavaScript
import { isGraphQLError, createGraphQLError } from '../../error.js';
// JSON stringifier that adjusts the result error extensions while serialising
export function jsonStringifyResult(result) {
return JSON.stringify(Array.isArray(result)
? result.map(omitInternalsFromResultErrors)
: omitInternalsFromResultErrors(result));
}
function omitInternalsFromResultErrors(result) {
return {
...result,
errors: result.errors?.map(omitInternalsFromError),
};
}
function omitInternalsFromError(err) {
if (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 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;
}