apollo-logger
Advanced tools
Comparing version 0.1.1 to 0.2.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link'], factory) : | ||
(factory((global.apolloLogger = {}),global.apolloLink)); | ||
}(this, (function (exports,apolloLink) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
"use strict"; | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
@@ -52,2 +53,5 @@ var extendStatics = Object.setPrototypeOf || | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var graphql_1 = require("graphql"); | ||
var apollo_link_1 = require("apollo-link"); | ||
function debug() { | ||
@@ -151,39 +155,35 @@ var args = []; | ||
LoggingLink.prototype.request = function (operation, forward) { | ||
var observable = forward(operation); | ||
if (observable.map) { | ||
return observable.map(function (result) { | ||
debug(JSON.stringify(result) + " <= " + formatRequest(operation)); | ||
return result; | ||
}); | ||
} | ||
else { | ||
return new apolloLink.Observable(function (observer) { | ||
var operationAST = graphql_1.getOperationAST(operation.query, operation.operationName); | ||
var isSubscription = !!operationAST && operationAST.operation === 'subscription'; | ||
return new apollo_link_1.Observable(function (observer) { | ||
if (isSubscription) { | ||
debug("subscribe <= " + formatRequest(operation)); | ||
var observerProxy = { | ||
next: function (value) { | ||
debug(JSON.stringify(value) + " <= " + formatRequest(operation)); | ||
if (observer.next) { | ||
observer.next(value); | ||
} | ||
}, | ||
error: function (errorValue) { | ||
debug(JSON.stringify(errorValue) + " <= " + formatRequest(operation)); | ||
if (observer.error) { | ||
observer.error(errorValue); | ||
} | ||
}, | ||
complete: function () { | ||
debug("unsubscribe <= " + formatRequest(operation)); | ||
if (observer.complete) { | ||
observer.complete(); | ||
} | ||
}, | ||
}; | ||
observable.subscribe(observerProxy); | ||
} | ||
var sub = forward(operation).subscribe({ | ||
next: function (result) { | ||
debug(JSON.stringify(result) + " <= " + formatRequest(operation)); | ||
observer.next(result); | ||
}, | ||
error: function (error) { | ||
debug(JSON.stringify(error) + " <=e " + formatRequest(operation)); | ||
observer.error(error); | ||
}, | ||
complete: observer.complete.bind(observer), | ||
}); | ||
} | ||
return function () { | ||
if (isSubscription) { | ||
debug("unsubscribe <= " + formatRequest(operation)); | ||
} | ||
sub.unsubscribe(); | ||
}; | ||
}); | ||
}; | ||
return LoggingLink; | ||
}(apolloLink.ApolloLink)); | ||
var addApolloLogging = function (obj) { | ||
}(apollo_link_1.ApolloLink)); | ||
exports.LoggingLink = LoggingLink; | ||
exports.formatResponse = function (response, options) { | ||
debug(JSON.stringify(response) + " <= " + formatRequest(options)); | ||
return response; | ||
}; | ||
exports.addApolloLogging = function (obj) { | ||
if (obj.publish) { | ||
@@ -197,8 +197,3 @@ return addPubSubLogger(obj); | ||
exports.LoggingLink = LoggingLink; | ||
exports.addApolloLogging = addApolloLogging; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=bundle.umd.js.map |
@@ -1,6 +0,6 @@ | ||
/// <reference types="zen-observable" /> | ||
import { ApolloLink, NextLink, Operation, Observable } from 'apollo-link'; | ||
import { ApolloLink, Observable } from 'apollo-link'; | ||
export declare class LoggingLink extends ApolloLink { | ||
request(operation: Operation, forward: NextLink): Observable<any>; | ||
request(operation: any, forward: any): Observable<{}>; | ||
} | ||
export declare const formatResponse: (response: any, options: any) => any; | ||
export declare const addApolloLogging: (obj: any) => { | ||
@@ -7,0 +7,0 @@ publish(...args: any[]): any; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -46,3 +47,5 @@ var extendStatics = Object.setPrototypeOf || | ||
}; | ||
import { ApolloLink, Observable } from 'apollo-link'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var graphql_1 = require("graphql"); | ||
var apollo_link_1 = require("apollo-link"); | ||
function debug() { | ||
@@ -146,40 +149,35 @@ var args = []; | ||
LoggingLink.prototype.request = function (operation, forward) { | ||
var observable = forward(operation); | ||
if (observable.map) { | ||
return observable.map(function (result) { | ||
debug(JSON.stringify(result) + " <= " + formatRequest(operation)); | ||
return result; | ||
}); | ||
} | ||
else { | ||
return new Observable(function (observer) { | ||
var operationAST = graphql_1.getOperationAST(operation.query, operation.operationName); | ||
var isSubscription = !!operationAST && operationAST.operation === 'subscription'; | ||
return new apollo_link_1.Observable(function (observer) { | ||
if (isSubscription) { | ||
debug("subscribe <= " + formatRequest(operation)); | ||
var observerProxy = { | ||
next: function (value) { | ||
debug(JSON.stringify(value) + " <= " + formatRequest(operation)); | ||
if (observer.next) { | ||
observer.next(value); | ||
} | ||
}, | ||
error: function (errorValue) { | ||
debug(JSON.stringify(errorValue) + " <= " + formatRequest(operation)); | ||
if (observer.error) { | ||
observer.error(errorValue); | ||
} | ||
}, | ||
complete: function () { | ||
debug("unsubscribe <= " + formatRequest(operation)); | ||
if (observer.complete) { | ||
observer.complete(); | ||
} | ||
}, | ||
}; | ||
observable.subscribe(observerProxy); | ||
} | ||
var sub = forward(operation).subscribe({ | ||
next: function (result) { | ||
debug(JSON.stringify(result) + " <= " + formatRequest(operation)); | ||
observer.next(result); | ||
}, | ||
error: function (error) { | ||
debug(JSON.stringify(error) + " <=e " + formatRequest(operation)); | ||
observer.error(error); | ||
}, | ||
complete: observer.complete.bind(observer), | ||
}); | ||
} | ||
return function () { | ||
if (isSubscription) { | ||
debug("unsubscribe <= " + formatRequest(operation)); | ||
} | ||
sub.unsubscribe(); | ||
}; | ||
}); | ||
}; | ||
return LoggingLink; | ||
}(ApolloLink)); | ||
export { LoggingLink }; | ||
export var addApolloLogging = function (obj) { | ||
}(apollo_link_1.ApolloLink)); | ||
exports.LoggingLink = LoggingLink; | ||
exports.formatResponse = function (response, options) { | ||
debug(JSON.stringify(response) + " <= " + formatRequest(options)); | ||
return response; | ||
}; | ||
exports.addApolloLogging = function (obj) { | ||
if (obj.publish) { | ||
@@ -186,0 +184,0 @@ return addPubSubLogger(obj); |
{ | ||
"name": "apollo-logger", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Apollo GraphQL Logger", | ||
@@ -47,2 +47,5 @@ "main": "./lib/bundle.umd.js", | ||
"apollo-link": "^1.0.0", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^4.1.3", | ||
"prettier": "^1.6.1", | ||
"graphql": "^0.11.7", | ||
@@ -52,2 +55,4 @@ "rimraf": "^2.6.2", | ||
"tslint": "^5.2.0", | ||
"tslint-config-prettier": "^1.5.0", | ||
"tslint-plugin-prettier": "^1.3.0", | ||
"typescript": "^2.3.2" | ||
@@ -61,3 +66,18 @@ }, | ||
"debug": "^3.0.1" | ||
}, | ||
"lint-staged": { | ||
"*.ts": [ | ||
"tslint --fix", | ||
"git add" | ||
], | ||
"*.{json}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"prettier": { | ||
"printWidth": 120, | ||
"singleQuote": true, | ||
"parser": "babylon" | ||
} | ||
} |
@@ -15,6 +15,7 @@ ## Apollo GraphQL Logger | ||
- Apollo Link | ||
- Apollo Express Server | ||
- And PubSub | ||
``` js | ||
import { LoggingLink, addApolloLogging } from 'apollo-logger'; | ||
import { LoggingLink, addApolloLogging, formatResponse } from 'apollo-logger'; | ||
@@ -26,2 +27,8 @@ const link = ApolloLink.from([ | ||
... | ||
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: myGraphQLSchema, formatResponse }); | ||
... | ||
const pubsub = addApolloLogging(new PubSub()); | ||
@@ -28,0 +35,0 @@ ``` |
@@ -1,2 +0,3 @@ | ||
import { ApolloLink, NextLink, Operation, Observable } from 'apollo-link'; | ||
import { print, getOperationAST } from 'graphql'; | ||
import { ApolloLink, Observable } from 'apollo-link'; | ||
@@ -61,43 +62,38 @@ function debug(...args) { | ||
export class LoggingLink extends ApolloLink { | ||
request(operation: Operation, forward: NextLink): Observable<any> { | ||
const observable = forward(operation); | ||
if (observable.map) { | ||
return observable.map(result => { | ||
debug(`${JSON.stringify(result)} <= ${formatRequest(operation)}`); | ||
return result; | ||
}); | ||
} else { | ||
return new Observable(observer => { | ||
request(operation, forward) { | ||
const operationAST = getOperationAST(operation.query, operation.operationName); | ||
const isSubscription = !!operationAST && operationAST.operation === 'subscription'; | ||
return new Observable(observer => { | ||
if (isSubscription) { | ||
debug(`subscribe <= ${formatRequest(operation)}`); | ||
const observerProxy = { | ||
next(value) { | ||
debug(`${JSON.stringify(value)} <= ${formatRequest(operation)}`); | ||
} | ||
const sub = forward(operation).subscribe({ | ||
next: result => { | ||
debug(`${JSON.stringify(result)} <= ${formatRequest(operation)}`); | ||
if (observer.next) { | ||
observer.next(value); | ||
} | ||
}, | ||
error(errorValue) { | ||
debug(`${JSON.stringify(errorValue)} <= ${formatRequest(operation)}`); | ||
observer.next(result); | ||
}, | ||
error: error => { | ||
debug(`${JSON.stringify(error)} <=e ${formatRequest(operation)}`); | ||
if (observer.error) { | ||
observer.error(errorValue); | ||
} | ||
}, | ||
complete() { | ||
debug(`unsubscribe <= ${formatRequest(operation)}`); | ||
if (observer.complete) { | ||
observer.complete(); | ||
} | ||
}, | ||
}; | ||
observable.subscribe(observerProxy); | ||
observer.error(error); | ||
}, | ||
complete: observer.complete.bind(observer), | ||
}); | ||
} | ||
return () => { | ||
if (isSubscription) { | ||
debug(`unsubscribe <= ${formatRequest(operation)}`); | ||
} | ||
sub.unsubscribe(); | ||
} | ||
}); | ||
} | ||
} | ||
export const formatResponse = (response, options) => { | ||
debug(`${JSON.stringify(response)} <= ${formatRequest(options)}`); | ||
return response; | ||
} | ||
export const addApolloLogging = obj => { | ||
@@ -104,0 +100,0 @@ if (obj.publish) { |
Sorry, the diff of this file is not supported yet
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
47513
90
13
487