apollo-logger
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -59,3 +59,3 @@ "use strict"; | ||
if (apolloLogging) { | ||
console.log(formatRequest(request), "=>", JSON.stringify(result)); | ||
console.log(formatRequest(request), '=>', JSON.stringify(result)); | ||
} | ||
@@ -71,7 +71,7 @@ return [7]; | ||
try { | ||
var logHandler = function (error, result) { | ||
var logHandler = function (err, res) { | ||
if (apolloLogging) { | ||
console.log(JSON.stringify(error ? error : result)); | ||
console.log(err ? "error caught: " + JSON.stringify(err) : JSON.stringify(res)); | ||
} | ||
return handler(error, result); | ||
return handler(err, res); | ||
}; | ||
@@ -82,3 +82,3 @@ result = netIfc.subscribe(request, logHandler); | ||
if (apolloLogging) { | ||
console.log(formatRequest(request), "=> subscription:", result); | ||
console.log(formatRequest(request), '=> subscription:', result); | ||
} | ||
@@ -94,6 +94,6 @@ } | ||
if (apolloLogging) { | ||
console.log("unsubscribe from subscription:", subId); | ||
console.log('unsubscribe from subscription:', subId); | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
@@ -118,3 +118,3 @@ }; | ||
logHandler = !apolloLogging ? handler : function (msg) { | ||
console.log("pubsub msg", opName + "(" + JSON.stringify(msg) + ")"); | ||
console.log('pubsub msg', opName + "(" + JSON.stringify(msg) + ")"); | ||
return handler(msg); | ||
@@ -128,3 +128,3 @@ }; | ||
if (apolloLogging) { | ||
console.log('pubsub subscribe', opName, "=>", result); | ||
console.log('pubsub subscribe', opName, '=>', result); | ||
} | ||
@@ -144,2 +144,45 @@ return [7]; | ||
return pubsub.unsubscribe.apply(pubsub, args); | ||
}, | ||
asyncIterator: function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var asyncIter = pubsub.asyncIterator.apply(pubsub, args); | ||
var trigger = args[0]; | ||
return Object.assign({}, asyncIter, { | ||
next: function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, , 2, 3]); | ||
return [4, asyncIter.next()]; | ||
case 1: | ||
result = _a.sent(); | ||
return [3, 3]; | ||
case 2: | ||
if (apolloLogging) { | ||
console.log(trigger + "->next =>", JSON.stringify(result)); | ||
} | ||
return [7]; | ||
case 3: return [2, result]; | ||
} | ||
}); | ||
}); | ||
}, | ||
throw: function (error) { | ||
var result; | ||
try { | ||
result = asyncIter.throw(error); | ||
} | ||
finally { | ||
if (apolloLogging) { | ||
console.log(trigger + ("->throw(\"" + JSON.stringify(error) + "\") =>"), JSON.stringify(result)); | ||
} | ||
} | ||
return result; | ||
} | ||
}); | ||
} | ||
@@ -150,11 +193,11 @@ }); }; | ||
manager.setupFunctions = {}; | ||
var _loop_1 = function (key) { | ||
manager.setupFunctions[key] = function (opts, args, name) { | ||
var triggerMap = setupFunctions[key](opts, args, name); | ||
var _loop_1 = function (func) { | ||
manager.setupFunctions[func] = function (opts, args, name) { | ||
var triggerMap = setupFunctions[func](opts, args, name); | ||
var loggedMap = {}; | ||
var _loop_2 = function (key_1) { | ||
loggedMap[key_1] = Object.assign({}, triggerMap[key_1]); | ||
var originalFilter = triggerMap[key_1].filter; | ||
var _loop_2 = function (key) { | ||
loggedMap[key] = Object.assign({}, triggerMap[key]); | ||
var originalFilter = triggerMap[key].filter; | ||
if (originalFilter) { | ||
loggedMap[key_1].filter = function (val, ctx) { | ||
loggedMap[key].filter = function (val, ctx) { | ||
var result; | ||
@@ -166,4 +209,4 @@ try { | ||
if (apolloLogging) { | ||
console.log("pubsub filter " + key_1 + "(opts = " + JSON.stringify(opts) + ", args = " + JSON.stringify(args) + ", name = " + name + ")"); | ||
console.log("." + key_1 + "(val = " + JSON.stringify(val) + ", ctx = " + JSON.stringify(ctx) + ") =>", result); | ||
console.log("pubsub filter " + key + "(opts = " + JSON.stringify(opts) + ", args = " + JSON.stringify(args) + ", name = " + name + ")"); | ||
console.log("." + key + "(val = " + JSON.stringify(val) + ", ctx = " + JSON.stringify(ctx) + ") =>", result); | ||
} | ||
@@ -176,4 +219,4 @@ } | ||
for (var _i = 0, _a = Object.keys(triggerMap); _i < _a.length; _i++) { | ||
var key_1 = _a[_i]; | ||
_loop_2(key_1); | ||
var key = _a[_i]; | ||
_loop_2(key); | ||
} | ||
@@ -184,4 +227,4 @@ return loggedMap; | ||
for (var _i = 0, _a = Object.keys(setupFunctions); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
_loop_1(key); | ||
var func = _a[_i]; | ||
_loop_1(func); | ||
} | ||
@@ -188,0 +231,0 @@ return manager; |
{ | ||
"name": "apollo-logger", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Apollo GraphQL Logger", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -25,3 +25,3 @@ let apolloLogging = true; | ||
if (apolloLogging) { | ||
console.log(JSON.stringify(err ? err : res)); | ||
console.log(err ? "error caught: " + JSON.stringify(err) : JSON.stringify(res)); | ||
} | ||
@@ -68,2 +68,26 @@ return handler(err, res); | ||
}, | ||
asyncIterator(...args) { | ||
const asyncIter = pubsub.asyncIterator(...args); | ||
const trigger = args[0]; | ||
return Object.assign({}, asyncIter, { | ||
async next() { | ||
let result; | ||
try { | ||
result = await asyncIter.next(); | ||
} finally { | ||
if (apolloLogging) { console.log(trigger + "->next =>", JSON.stringify(result)); } | ||
} | ||
return result; | ||
}, | ||
throw(error) { | ||
let result; | ||
try { | ||
result = asyncIter.throw(error); | ||
} finally { | ||
if (apolloLogging) { console.log(trigger + `->throw("${JSON.stringify(error)}") =>`, JSON.stringify(result)); } | ||
} | ||
return result; | ||
} | ||
}); | ||
} | ||
}); | ||
@@ -70,0 +94,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23083
351