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

@nearform/trail-fastify-graphql-plugin

v6.0.0

Published

Fastify plugin providing graphql endpoints for the audit trail logging service

Downloads

9

Readme

@nearform/trail-fastify-graphql-plugin

npm

trail-fastify-graphql-plugin is a Fastify plugin which adds a graphql endpoint for querying trail data.

Install

To install via npm:

npm install @nearform/trail-fastify-graphql-plugin

Usage

const Fastify = require('fastify')

const main = async function() {
  const fastify = Fastify()

  fastify.register(require('@nearform/trail-fastify-graphql-plugin'))

  await fastify.listen(3000, console.log)
}

main().catch(console.error)

Graphql queries can then be submitted to the /graphql path as either GET or POST requests. If using a GET request then specify the query to be executed in a request parameter named query. If using a POST request then the query can be specified in the request body as either JSON or graphql. See the fastify-gql module for details.

Configuration

The plugin takes the following configuration options:

  • logger: A logger to be passed to the trails manager.
  • db: Database settings for the trails manager.
  • pool: A pre-configured database pool to be used by the trails manager; used in preference to any specified database settings.
  • trailsManager: A pre-configured trails manager instance; used in preference to any of the previous settings.

Graphql schema

Queries

The schema provides the following queries:

  • trail(id: Int!): Fetch a trail record by ID.
  • trails(from: Date!, to: Date!, ...): Search for trail records within a specified date range, and optionally filter by additional values.
  • enumerateTrails(from: Date!, to: Date!, type: TrailType!, ...): Return an enumeration of trails of the specified type, within the specified date range.

Mutations

The schema provides the following mutations:

  • insertTrail(when: Date!, who: StringWithAttrs!, what: StringWithAttrs!, subject: StringWithAttrs!, where: JSON, why: JSON, meta: JSON): Insert a new trail record.
  • updateTrail(id: Int!, when: Date!, who: StringWithAttrs!, what: StringWithAttrs!, subject: StringWithAttrs!, where: JSON, why: JSON, meta: JSON): Update a trail record.
  • deleteTrail(id: Int!): Delete a trail record.

String values

Some trail record fields support attributed string values (indicated by the StringWithAttrs type) when inserting or updating. When writing fields of this type, the value can be specified either as an object with an id property (specifying the string value) and additional properties which specify the string's attributes; or as a simple string value when no additional attributes are needed.

For example:

  • String with attributes: { id: "the string", attr0: "this", attr1: 1 }
  • String with no attributes: "the string" - equivalent to { id: "the string" }

Sample queries

Get a trail record

{
    trail(id: 123) {
        id
        when
        subject
    }
}

Search for trail records

{
    trails(from: "2018-01-01T12:34:56.000Z", to: "2018-01-05T12:34:56.000Z") {
        id
        when
        who
        what
        subject
    }
}

Enumerate trail records

{
    enumerateTrails(from: "2018-01-01T12:34:56.000Z", to: "2018-01-05T12:34:56.000Z", type: WHO)
}

Insert a new trail record

mutation {
    insertTrail(when: "2018-01-01T12:34:56.000Z", who: "A Person", what: "A thing", subject: "Substance") {
        id
        when
        who
        what
        subject
        meta
        where
        why
    }
}

Insert a new trail record with attributed strings

mutation {
    insertTrail(when: "2018-01-01T12:34:56.000Z", who: { id: "A Person", attr: 10 }, what: { id: "A thing", attr: 20 }, subject: "Substance") {
        id
        when
        who
        what
        subject
        meta
        where
        why
    }
}

Update an existing trail record

mutation {
    updateTrail(id: 123, when: "2018-01-01T12:34:56.000Z", who: "A N Other", what: "Something else", subject: "Object")
}

Delete a trail record

mutation {
    deleteTrail(id: 123)
}

License

Copyright nearForm Ltd 2020. Licensed under MIT.