npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@graphql-debugger/trace-directive

v0.0.0-alpha.109

Published

- [graphql-debugger.com](http://www.graphql-debugger.com)

Downloads

55

Readme

@graphql-debugger/trace-directive

npm version License: MIT

About

Place the @trace directive on any fields you wish to trace.

type User {
  name: String
  age: Int
  balance: Int @trace
  posts: [Post] @trace
}

type Post {
  title: String
  comments: [Comment] @trace
}

type Comment {
  content: String
}

Given the query:

query {
  users {
    name
    balance
    posts {
      title
      comments {
        content
      }
    }
  }
}

Outputting the following traces:

Traces

Getting Started

Running Jaeger UI

  • https://www.jaegertracing.io/

This is an open-source collector, and it comes with a graphical interface. You collect the traces and spans from your GraphQL server and send export them to here. Then, once they are sent, you can visualize them like the image above.

To start this interface, I suggest you use Docker. Here is an all-in-one script to start jager.

docker run --rm --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.35

Then you can go to http://localhost:16686/ to open the UI.

Boilerplate

Quickstart boilerplate.

index.ts:

import {
  GraphQLDebuggerContext,
  setupOtel,
  traceDirective,
} from "@graphql-debugger/trace-directive";

import { makeExecutableSchema } from "@graphql-tools/schema";
import { createServer } from "@graphql-yoga/node";
import util from "util";

setupOtel();
const sleep = util.promisify(setTimeout);

const typeDefs = `
    type User {
      name: String
      age: Int
      balance: Int @trace
      posts: [Post] @trace
    }

    type Post {
      title: String
      comments: [Comment] @trace
    }

    type Comment {
      content: String
    }

    type Query {
      users: [User] @trace
    }
`;

const resolvers = {
  Query: {
    users: async () => {
      await sleep(200);
      return [{ name: "Dan", age: 23 }];
    },
  },
  User: {
    balance: async () => {
      await sleep(100);
      return 100;
    },
    posts: async () => {
      await sleep(500);
      return [{ title: "Beer Is Cool" }];
    },
  },
  Post: {
    comments: async () => {
      await sleep(300);
      return [
        {
          content: "I also think beer is cool",
        },
      ];
    },
  },
};

const trace = traceDirective();

let schema = makeExecutableSchema({
  typeDefs: [typeDefs, trace.typeDefs],
  resolvers,
});

schema = trace.transformer(schema);

const server = createServer({
  schema,
  port: 5000,
  context: {
    GraphQLDebuggerContext: new GraphQLDebuggerContext({
      schema,
    }),
  },
});

server
  .start()
  .then(() => console.log("server online"))
  .catch(console.error);

Context Value

Inject the GraphQLDebuggerContext instance inside your GraphQL request context.

import { GraphQLDebuggerContext } from "@graphql-debugger/trace-directive";

const myServer = new GraphQLServerFooBar({
  schema,
  context: {
    GraphQLDebuggerContext: new GraphQLDebuggerContext({
      schema,
    }),
  },
});

Exporting traces

This package does not export traces to your collector, you must set this up yourself. Checkout the quickstart boilerplate setup-otel file in this document.

Resources

  • https://www.jaegertracing.io/
  • https://opentelemetry.io/
  • https://www.the-guild.dev/graphql/tools/docs/schema-directives

License

MIT - Rocket Connect - https://github.com/rocket-connect