项目作者: sysgears

项目描述 :
Apollo GraphQL Logger
高级语言: TypeScript
项目地址: git://github.com/sysgears/apollo-logger.git
创建时间: 2017-05-12T19:08:31Z
项目社区:https://github.com/sysgears/apollo-logger

开源协议:MIT License

下载


Apollo GraphQL Logger

npm version
Twitter Follow

Installation

  1. 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
  1. import { LoggingLink, wrapPubSub, formatResponse } from 'apollo-logger';
  2. const logOptions = { logger: console.log };
  3. const link = ApolloLink.from([
  4. new LoggingLink(logOptions),
  5. new HttpLink({uri: ...})
  6. );
  7. ...
  8. app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: myGraphQLSchema, formatResponse: formatResponse.bind(logOptions) });
  9. ...
  10. const pubsub = wrapPubSub(new PubSub(), logOptions);

Sample output

On each example the result of operation comes after =>

  • Query:

    1. {"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:

    1. {"data":{"addCounter":{"amount":21,"__typename":"Counter"}}} <= addCounter({"amount":1})
  • Subscription

    1. subscribe <= onPostUpdated({"endCursor":11})
  • Subscription message:

    1. {"data":{"counterUpdated":{"amount":21,"__typename":"Counter"}}} <= onCounterUpdated
  • Unsubscription

    1. unsubscribe <= onPostUpdated({"endCursor":11})
  • PubSub publish on a server:

    1. pubsub publish [ 'countUpdated',
    2. { id: 1, created_at: null, updated_at: null, amount: 7 } ]
  • PubSub subscribe on a server:

    1. pubsub subscribe postsUpdated => 2
  • PubSub unsubscribe on a server:

    1. pubsub unsubscribe [ 2 ]
  • PubSub message generated on a server:

    1. 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.