Skip to content

Instantly share code, notes, and snippets.

View avalla's full-sized avatar
🤣
behind every kiss a potential judas

Andrea Valla avalla

🤣
behind every kiss a potential judas
View GitHub Profile
@avalla
avalla / graphql-apollo-moleculer-error-formatter.js
Last active June 7, 2019 12:41 — forked from mdlavin/graphql-apollo-xray-error-formatter.js
An Apollo Server formatError function that avoids "Converting circular structure to JSON" errors
// This is the attribute that continuation local storage uses to hold onto
const CLS_CONTEXT_ATTRIBUTE = 'ctx';
// A formatError function that can be used with
// https://www.apollographql.com/docs/apollo-server/features/errors#for-the-client-response
function formatError (err) {
// The continuation-local-storage module attaches a context attribute to
// errors so that the context can be resolved from errors. The attribute
// is enumerable by default and so it gets included in GraphQL error
// reporing. That alone would not be a problem, but moleculer's context