Skip to content

Commit 4dd3c7e

Browse files
authored
Merge pull request #3 from addityasingh/as-publish
feat: Add example and changes to publish
2 parents 7983d94 + 9fcf495 commit 4dd3c7e

File tree

11 files changed

+799
-7
lines changed

11 files changed

+799
-7
lines changed

.github/workflows/nodejs.yml renamed to .github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Node CI
1+
name: build
22

33
on: [push]
44

.github/workflows/publish.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 12
15+
registry-url: https://registry.npmjs.org/
16+
- run: yarn install
17+
- run: yarn build
18+
- run: npm publish --access public
19+
env:
20+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.github
2+
src
3+
node_modules
4+
examples
5+
tsconfig.json
6+
dist/__tests__

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
# graphql-lightstep-middleware
22

3+
[![NPM](https://nodei.co/npm/graphql-lightstep-middleware.png)](https://npmjs.org/package/graphql-lightstep-middleware)
4+
35
GraphQL middleware to instrument resolvers with opentracing traces for lightstep collector
46

5-
## Usage
7+
![build](https://github.com/addityasingh/graphql-lightstep-middleware/workflows/build/badge.svg)
8+
[![downloads](https://img.shields.io/npm/dt/graphql-lightstep-middleware.svg)](https://npmjs.org/package/graphql-lightstep-middleware?cacheSeconds=3600)
9+
[![version](https://img.shields.io/npm/v/graphql-lightstep-middleware.svg)](https://npmjs.org/package/graphql-lightstep-middleware?cacheSeconds=3600)
10+
11+
## Table of contents
12+
13+
- [Getting started](#getting-started)
14+
- [API](#api)
15+
- [Contributing](#contributing)
16+
- [Code of Conduct](#code-of-conduct)
17+
- [Contributing](#contributing)
18+
- [Good first issues](#good-first-issues)
19+
- [License](#licence)
20+
21+
## Getting started
622

723
1. Install the package and graphql-middleware
824

@@ -85,4 +101,32 @@ app.use(
85101
);
86102
```
87103

88-
## Development
104+
## API
105+
106+
### middleware = graphqlLightstepMiddleware([options])
107+
108+
- `options`
109+
- `tracer`: An optional `lightstep` tracer object
110+
- `hooks`: Lost of `PreResolve` and `PostResolve` hooks
111+
112+
Refer the [examples](./examples) for more usage examples
113+
114+
## Contributing
115+
116+
`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
117+
118+
### Code of Conduct
119+
120+
Please check the [CODE OF CONDUCT](./CODE_OF_CONDUCT) which we have in place to ensure safe and supportive environment for contributors
121+
122+
### Contributing
123+
124+
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
125+
126+
### Good first issues
127+
128+
Please check issues labeled [#good-first-issues](https://github.com/addityasingh/graphql-lightstep-middleware/labels/good%20first%20issue) under the issues section
129+
130+
## Licence
131+
132+
`graphql-lightstep-middleware` uses [MIT License](./LICENSE)

examples/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Verifying `graphql-lightstep-middleware` example can be done with below setup
2+
3+
## Run lightstep satelite
4+
5+
To test lightstep locally, we need to first run `lightstep` satelite for developer mode. This is documented on lightstep site [Use Developer mode](https://docs.lightstep.com/docs/use-developer-mode-to-quickly-see-traces)
6+
7+
## Run example
8+
9+
To run the example for `graphql-with-lightstep` run
10+
11+
```sh
12+
yarn run tsc && node dist/graphql-with-lightstep.js
13+
```
14+
15+
## Result
16+
17+
If the setup works correctly, you would see below event in lightstep dashboard
18+
![trace event](https://user-images.githubusercontent.com/5351262/73496357-adf85d00-43b8-11ea-85c2-468f10afbf2f.png)
19+
and the corresponding trace as below
20+
![trace view](https://user-images.githubusercontent.com/5351262/73496358-adf85d00-43b8-11ea-9b56-f53c5a6b2220.png)

examples/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "examples",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "tsc",
8+
"test": "jest"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"express": "^4.17.1",
15+
"express-graphql": "^0.9.0",
16+
"graphql-tools": "^4.0.6",
17+
"lightstep-tracer": "^0.25.1"
18+
},
19+
"devDependencies": {
20+
"typescript": "^3.7.5"
21+
}
22+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import express from "express";
2+
import { applyMiddleware } from "graphql-middleware";
3+
import { makeExecutableSchema } from 'graphql-tools';
4+
const graphqlExpressHttp = require("express-graphql");
5+
import { initGlobalTracer, globalTracer } from "opentracing";
6+
import { Tracer as LightstepTracer } from "lightstep-tracer";
7+
import graphqlLightstepMiddleware from '../../dist/index.js';
8+
9+
10+
// Initialise the lightstep tracer
11+
initGlobalTracer(new LightstepTracer({
12+
access_token: "developer",
13+
component_name: "graphql-lightstep-middleware",
14+
collector_host: "localhost",
15+
collector_port: 8360,
16+
plaintext: true,
17+
collector_encryption: "none"
18+
} as any));
19+
20+
// Construct a schema, using GraphQL schema language
21+
const typeDefs = `
22+
type Query {
23+
hello(name: String): String
24+
}
25+
`;
26+
27+
// The root provides a resolver function for each API endpoint
28+
const resolvers = {
29+
Query: {
30+
hello: (parent, args, context) => {
31+
const result = `Hello ${args.name ? args.name : "world"}!`;
32+
// The rootSpan is available in the context now
33+
context.tracing.rootSpan.addTags({
34+
helloResolver: result
35+
});
36+
return result;
37+
},
38+
}
39+
};
40+
41+
const lightstepMiddleware = graphqlLightstepMiddleware({
42+
tracer: globalTracer()
43+
});
44+
45+
const schema = applyMiddleware(
46+
makeExecutableSchema({typeDefs, resolvers}),
47+
lightstepMiddleware,
48+
)
49+
50+
const app = express();
51+
app.use("/graphql", graphqlExpressHttp({
52+
schema: schema,
53+
rootValue: resolvers,
54+
graphiql: true,
55+
}))
56+
57+
app.listen(4001, () => {
58+
console.log('Running a GraphQL API server at http://localhost:4000/graphql');
59+
});

examples/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"rootDir": "./src",
4+
"outDir": "./dist",
5+
"target": "es5",
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"sourceMap": true,
9+
"declaration": true,
10+
"noImplicitAny": false,
11+
"allowSyntheticDefaultImports": false,
12+
"esModuleInterop": true,
13+
"pretty": true,
14+
"removeComments": true,
15+
"lib": ["es6", "esnext.asynciterable"]
16+
},
17+
"exclude": ["node_modules", "dist"]
18+
}

0 commit comments

Comments
 (0)