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

@hydre/shimio-graphql

v5.0.5

Published

A GraphQL server and client built on Shimio

Downloads

7

Readme

Table of content

Installation

npm install @hydre/shimio-graphql

Quick start

Server exemple

import { readFileSync } from 'fs'
import { dirname, join } from 'path'
import { PassThrough } from 'stream'
import { fileURLToPath } from 'url'
import Server from '@hydre/shimio/server'
import Serve from '@hydre/shimio-graphql/serve'
import graphql from 'graphql'
import Koa from 'koa'

const directory = dirname(fileURLToPath(import.meta.url))
const WAIT = 150
const file = readFileSync(join(directory, 'schema.gql'), 'utf-8')
const server = Server({
  koa: new Koa(),
  // context here is an empty object created by Shimio server
  on_upgrade: ({ context }) => {
    context.through = new PassThrough({ objectMode: true })
    return true
  },
  on_socket: Serve({
    context: async ({
      // the raw upgraded socket
      socket,
      // the raw connection context (in allow_upgrade)
      context,
      // the raw first http request
      request
    }) => ({
      // put whatever you want here
      // this is to build a per-operation context
      // each batch of queries will have a clean context
    }),
    schema: graphql.buildSchema(file),
    query : {
      me() {
        return { name: 'pepeg' }
      },
      ping() {
        return 'ping pong chin chan'
      },
    },
    mutation: {
      sendMessage({ message }, { through }) {
        through.write({ onMessage: message })
        return 'message sent!'
      },
    },
    subscription: {
      async *onMessage(_, { through }) {
        for await (const chunk of through) {
          await new Promise(resolve =>
            setTimeout(resolve, WAIT))
          yield chunk
        }
      },
    },
  }),
})

await server.listen(3000)
console.log('running on :3000')

Client example

import debug from 'debug'
import casual from 'casual'
import { inspect } from 'util'
import Client from '@hydre/shimio/client'
import Query from '@hydre/shimio-graphql/query'

// || ===========================================
// || When running in nodejs you need to provide a ws polyfill
// || Browsers have it by default
// ||
import ws from 'ws'
globalThis.WebSocket = ws
// ||
// || ===========================================

// see options in @hydre/shimio
const client = Client({ host: 'ws://0.0.0.0:3000' })
const query = Query(client)
const END = 2000

await client.connect()

const {
  listen, // an asyncIterator yielding updates
  stop, // close the channel
  once // promise of the first result only
} = await query(/* GraphQL */ `
 query pang {
   ping
 }

 mutation hello {
   first: sendMessage(message: "howdy")
   then: sendMessage(message: "pls sir show vagana")
 }

 subscription hey_listen {
   onMessage
 }
`)

setTimeout(() => {
  stop() // unsubscribe from operation
}, END)

for await (const chunk of listen())
  console.log('received', inspect(chunk, false, Infinity, true))

client.disconnect()