项目作者: addityasingh

项目描述 :
GraphQL middleware to instrument resolvers with opentracing traces for lightstep collector
高级语言: TypeScript
项目地址: git://github.com/addityasingh/graphql-lightstep-middleware.git
创建时间: 2020-01-25T22:06:22Z
项目社区:https://github.com/addityasingh/graphql-lightstep-middleware

开源协议:MIT License

下载


graphql-lightstep-middleware

NPM

GraphQL middleware to instrument and augment resolvers with opentracing traces for lightstep collector

build
downloads
version

Table of contents

Getting started

  1. Install the package and graphql-middleware
  1. yarn add graphql-lightstep-middleware
  2. yarn add graphql-middleware
  1. Create the lightstep global tracer
  1. import { initGlobalTracer } from "opentracing";
  2. import { Tracer as LightstepTracer } from "lightstep-tracer";
  3. // Initialise the lightstep tracer
  4. initGlobalTracer(new LightstepTracer({
  5. access_token: "developer",
  6. component_name: "graphql-lightstep-middleware",
  7. collector_host: "localhost",
  8. collector_port: 8360,
  9. plaintext: true,
  10. collector_encryption: "none"
  11. } as any));
  1. Configure the middleware
  1. import graphqlLightstepMiddleware from "graphql-lightstep-middleware";
  2. // create the lightstep-graphql-middleware
  3. const lightstepMiddleware = graphqlLightstepMiddleware({
  4. tracer: globalTracer()
  5. });
  1. Apply the middleware to the schema
  1. import express from "express";
  2. import graphqlExpressHttp from "express-graphql";
  3. import { applyMiddleware } from "graphql-middleware";
  4. import { makeExecutableSchema } from "graphql-tools";
  5. // Construct a schema, using GraphQL schema language
  6. const typeDefs = `
  7. type Query {
  8. hello(name: String): String
  9. }
  10. `;
  11. const resolvers = {
  12. Query: {
  13. hello: (parent, args, context) => {
  14. const result = `Hello ${args.name ? args.name : "world"}!`;
  15. // The rootSpan is available in the context now
  16. context.tracing.rootSpan.addTags({
  17. helloResolver: result
  18. });
  19. return result;
  20. }
  21. }
  22. };
  23. // apply the middleware to the schema
  24. const schema = applyMiddleware(
  25. makeExecutableSchema({ typeDefs, resolvers }),
  26. lightstepMiddleware
  27. );
  28. // Use the schema in your graphql server
  29. const app = express();
  30. app.use(
  31. "/graphql",
  32. graphqlExpressHttp({
  33. schema: schema,
  34. rootValue: resolvers,
  35. graphiql: true
  36. })
  37. );

API

middleware = graphqlLightstepMiddleware([options])

  • options
    • tracer: An optional lightstep tracer object
    • hooks: Lost of PreResolve and PostResolve hooks

Refer the examples for more usage examples

Contributing

graphql-lightstep-middleware package intends to support contribution and support and thanks the open source community to making it better. Read below to learn how you can improve this repository and package

Code of Conduct

Please check the CODE OF CONDUCT which we have in place to ensure safe and supportive environment for contributors

Contributing

Feel free to create issues and bugs in the issues section using issues and bugs template. Please also ensure that there are not existing issues created on the same topic

Good first issues

Please check issues labeled #good-first-issues under the issues section

Licence

graphql-lightstep-middleware uses MIT License