diff --git a/src/GraphQL/Client/Query.js b/src/GraphQL/Client/Query.js new file mode 100644 index 0000000..ae1329d --- /dev/null +++ b/src/GraphQL/Client/Query.js @@ -0,0 +1,20 @@ +const formatError = (err) => { + if (!err) return ""; + const props = ["message", "code", "syscall", "hostname", "address", "port"] + .filter((k) => err[k]) + .map((k) => `${k}: ${err[k]}`); + if (err.cause) props.push(`cause: ${formatError(err.cause)}`); + return props.join(", "); +}; + +export const cause = (err) => { + const c = err.cause; + if (!c) return ""; + if (c instanceof AggregateError) { + return [ + c.message, + ...Array.from(c.errors, (e, i) => `[${i}] ${formatError(e)}`), + ].join("\n"); + } + return formatError(c); +}; diff --git a/src/GraphQL/Client/Query.purs b/src/GraphQL/Client/Query.purs index a320056..16b24d1 100644 --- a/src/GraphQL/Client/Query.purs +++ b/src/GraphQL/Client/Query.purs @@ -43,6 +43,8 @@ import GraphQL.Client.Types (class GqlQuery, class QueryClient, Client(..), GqlR import GraphQL.Client.Variables (class VarsTypeChecked, getVarsJson, getVarsTypeNames) import Type.Proxy (Proxy(..)) +foreign import cause :: Error -> String + -- | Run a graphQL query with a custom decoder and custom options queryOptsWithDecoder :: forall client directives schema query returns queryOpts mutationOpts sr @@ -261,6 +263,8 @@ addErrorInfo schema queryName q = <> show queryName <> ".\nerror: " <> message err + <> ".\ncause: " + <> cause err <> ".\nquery: " <> queryName <> " "