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

hapi-graphql-graffiti

v3.1.1

Published

PERSONAL FORK of @risingstack/graffiti with updates for hapi plugin

Downloads

15

Readme

graffiti

npm version Codeship Status for RisingStack/graffiti bitHound Overall Score Known Vulnerabilities

Currently the consumption of HTTP REST APIs dominate the client-side world, GraphQL aims to change this. This transition can be time-consuming - this is where graffiti comes into the picture.

We don't want to rewrite our application - no one wants that. graffiti provides an Express middleware, a Hapi plugin and a Koa middleware to convert your existing models into a GraphQL schema and exposes it over HTTP.

What is GraphQL?

GraphQL is a query language created by Facebook in 2012 which provides a common interface between the client and the server for data fetching and manipulations.

The client asks for various data from the GraphQL server via queries. The response format is described in the query and defined by the client instead of the server: they are called client‐specified queries.

For more info check out RisingStack's GraphQL tutorial.

Example server and queries

For a running example server and executable queries, check out our example repository and play with your GraphQL queries: graffiti-example

Adapters

Supported servers

Install

npm install @risingstack/graffiti --save

Usage

  1. run MongoDB
  2. register the middleware
  3. provide a schema (returned by an adapters getSchema method or your own GraphQLSchema instance)
  4. the GraphQL endpoint is available on /graphql

Express

import express from 'express';
import { json } from 'body-parser';
import graffiti from '@risingstack/graffiti';
import { getSchema } from '@risingstack/graffiti-mongoose';

import Cat from './models/Cat';
import User from './models/User';

const app = express();

// parse body as json
app.use(json());

app.use(graffiti.express({
  schema: getSchema([User, Cat]),
  context: {} // custom context
}));

app.listen(3000);

Hapi

import { Server } from 'hapi';
import graffiti from '@risingstack/graffiti';
import { getSchema } from '@risingstack/graffiti-mongoose';

const server = new Server();
server.connection({ port: 3000 });

server.register({
  register: graffiti.hapi,
  options: {
    schema: getSchema([User, Cat]),
    context: {} // custom context
  }
}, function (err) {
  if (err) {
    console.error('Failed to load plugin:', err);
  }

  server.start(function () {
      console.log('Server running at:', server.info.uri);
  });
});

Koa

import koa from 'koa';
import parser from 'koa-bodyparser';
import graffiti from '@risingstack/graffiti';
import { getSchema } from '@risingstack/graffiti-mongoose';

import Cat from './models/Cat';
import User from './models/User';

const app = koa();

app.use(parser());

app.use(graffiti.koa({
  schema: getSchema([User, Cat]),
  context: {} // custom context
}));

app.listen(3000);

Options

  • schema: a GraphQLSchema instance. You can use an adapters getSchema method, or provide your own schema. (required)
  • graphiql: may present GraphiQL when loaded directly from a browser. (default: true)
  • context: custom GraphQL context object. (default: {})

Test

npm test