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

@deep-foundation/hasura

v0.0.61

Published

[![npm](https://img.shields.io/npm/v/@deep-foundation/hasura.svg)](https://www.npmjs.com/package/@deep-foundation/hasura) [![Gitpod](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/deep-foundati

Downloads

811

Readme

npm Gitpod Discord

Usage

Library

See Documentation for examples and API

API

import { HasuraApi } from '@deep-foundation/hasura/api';

const api = new HasuraApi({
  path: 'hasura.domain.com',
  ssl: true,
  secret: 'adminsecretkey'
});

sql template literal for ide highlighting

import { sql } from '@deep-foundation/hasura/sql';

await api.sql(sql`SELECT * FROM mytable`);

hasura api reference

await api.query({
  type: 'track_table',
  args: {
    schema: 'public',
    name: 'mytable',
  }
});

Client

import { generateApolloClient } from '@deep-foundation/hasura/client';
import gql from 'graphql-tag';
const client = generateApolloClient({ // all options are optional
  ws: true, // need to socket for subscriptions // recommended
  secret: 'adminSecretForRoot', // admin secret for root access // not need when token exists
  token: 'tokenFromCookiesOrLocalStorage', // token for auth webhook auth // ignored when secret exists
  ssl: true; // auto http/https ws/wss protocol
  path: 'hasura.domain.com/path', // link to hasura location
  headers: {}, // custom additional fields into headers
  initialStore: {},
  relative: false, // optional
});
client.query({ query: gql`{ links { id }}` }).then(result => console.log(result))

If you need to specify an absolute path as protocol://domain.zone/path to hasura, you must pass these two options: path and ssl

const client = generateApolloClient({ // all options are optional
  ssl: true;
  path: 'hasura.domain.com/path',
});

If you need to specify relative path as /path to hasura, you must enable the relative mode with the relative option. In this case, the ssl option is ignored in http client, but used in ws. This can be useful when your build is with some proxy.

const client = generateApolloClient({ // all options are optional
  relative: true,
  path: 'hasura.domain.com/path',
});

You can also specify relative not locally in your code, but using an ENV variable DEEP_FOUNDATION_HASURA_RELATIVE or NEXT_PUBLIC_DEEP_FOUNDATION_HASURA_RELATIVE.

export DEEP_FOUNDATION_HASURA_RELATIVE = 1;

OR

export NEXT_PUBLIC_DEEP_FOUNDATION_HASURA_RELATIVE = 1;

Dignostics

PostgreSQL

Get PostgreSQL logs:

docker logs deep-postgres

Connect to PostgreSQL from inside its docker container:

docker exec -it deep-postgres bash
su postgres
psql

Get the size of all tables in the databases and indexes:

SELECT
  nspname                                               AS "schema",
  pg_class.relname                                      AS "table",
  pg_size_pretty(pg_total_relation_size(pg_class.oid))  AS "total_size",
  pg_size_pretty(pg_relation_size(pg_class.oid))        AS "data_size",
  pg_size_pretty(pg_indexes_size(pg_class.oid))         AS "index_size",
  pg_stat_user_tables.n_live_tup                        AS "rows",
  pg_size_pretty(
    pg_total_relation_size(pg_class.oid) / 
    (pg_stat_user_tables.n_live_tup + 1)
  )                                                     AS "total_row_size",
  pg_size_pretty(
    pg_relation_size(pg_class.oid) / 
    (pg_stat_user_tables.n_live_tup + 1)
  )                                                     AS "row_size"
FROM 
  pg_stat_user_tables 
JOIN 
  pg_class
ON
  pg_stat_user_tables.relid = pg_class.oid
JOIN 
  pg_catalog.pg_namespace AS ns
ON
  pg_class.relnamespace = ns.oid
ORDER BY 
  pg_total_relation_size(pg_class.oid) DESC;

Get the list of active queries:

SELECT datname, pid, state, query, age(clock_timestamp(), query_start) AS age 
FROM pg_stat_activity
WHERE state <> 'idle' 
    AND query NOT LIKE '% FROM pg_stat_activity %' 
ORDER BY age;

Cancel the query

SELECT pg_cancel_backend(pid);