Socket
Socket
Sign inDemoInstall

apollo-logger

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-logger

Apollo GraphQL Logger


Version published
Maintainers
1
Created
Source

Apollo GraphQL Logger

npm version Twitter Follow

Installation

npm install --save-dev apollo-logger

Usage

For full logging you will need to attach Apollo Logger to:

  • Apollo Link
  • Apollo Express Server
  • And PubSub
import { LoggingLink, wrapPubSub, formatResponse } from 'apollo-logger';

const logOptions = { logger: console.log };

const link = ApolloLink.from([
  new LoggingLink(logOptions),
  new HttpLink({uri: ...})
);

...

app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: myGraphQLSchema, formatResponse: formatResponse.bind(logOptions) });

...

const pubsub = wrapPubSub(new PubSub(), logOptions);

Sample output

On each example the result of operation comes after =>

  • Query:
{"data":{"post":{"id":20,"title":"Post title 20","content":"Post content 20","__typename":"Post","comments":[{"id":39,"content":"Comment title 1 for post 20","__typename":"Comment"},{"id":40,"content":"Comment title 2 for post 20","__typename":"Comment"}]}}} <= post({"id":"20"})
  • Mutation:
{"data":{"addCounter":{"amount":21,"__typename":"Counter"}}} <= addCounter({"amount":1})
  • Subscription
subscribe <= onPostUpdated({"endCursor":11})
  • Subscription message:
{"data":{"counterUpdated":{"amount":21,"__typename":"Counter"}}} <= onCounterUpdated
  • Unsubscription
unsubscribe <= onPostUpdated({"endCursor":11})
  • PubSub publish on a server:
pubsub publish [ 'countUpdated',
  { id: 1, created_at: null, updated_at: null, amount: 7 } ]
  • PubSub subscribe on a server:
pubsub subscribe postsUpdated => 2
  • PubSub unsubscribe on a server:
pubsub unsubscribe [ 2 ]
  • PubSub message generated on a server:
pubsub msg postsUpdated({"mutation":"CREATED","id":21,"node":{"id":21,"title":"New post 1"}})

License

Copyright © 2017 SysGears INC. This source code is licensed under the MIT license.

Keywords

FAQs

Package last updated on 15 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc