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

@bkonkle/graft

v1.1.0

Published

A ReasonML solution for type-safe querying against an automatic GraphQL backend

Downloads

8

Readme

Graft

A ReasonML solution for type-safe querying against an automatic GraphQL backend.

Graft helps you set up a Postgraphile backend based on PostgreSQL, Express, and Apollo, and then connect to it using ReasonML on the front end. An example client implementation will be included using reason-react and reason-apollo.

Setup

API

To set up a simple API follow the tag-monster-api example to quickly bootstrap a PostgreSQL database and introspect the schema to create an automatic GraphQL interface.

Bring your own ORM or query builder. The example above uses Knex, with a simple initial migration. Follow the instructions in the README to set up a root user and build the schema.

Next, set up an application-specific config file like this example.

From there, you can throw together a quick server init script like this example that uses Graft.Server.make() to start an Express server.

React Client

To connect to your brand new API from React, create a new ReasonML module in your React application to serve as your API Client. For more information on setting up ReasonML, take a look at the reason-react docs.

$ yarn add --dev @bkonkle/graft

bsconfig.json:

{
  "bs-dependencies": ["reason-react", "reason-apollo"],
  "ppx-flags": ["graphql_ppx/ppx"]
}

src/data/ApiClient.re:

let client =
  Graft.Client.make(
    ~uri=Config.Api.endpoint,
    ~getSession=Graft.Browser.Session.get,
    ~connectToDevTools=Config.Env.isDev ? true : false,
    (),
  );

Now, you can start querying with reason-apollo!

open Graft.Client;

module GetTag = [%graphql
  {|
    query GetTag($id: UUID!) {
      tagById(id: $id) {
        id
        name
        slug
      }
    }
  |}
];

let getTag =
  (. id) => ApiClient.client |> query(~request=GetTag.make(~id, ()));

/**
 * Plain JS interface
 */
let default = {"getTag": getTag};

This exposes a default export with a "getTag" property that allows plain JavaScript modules to use the getTag() function to fire queries. The return value is a standard Apollo Client promise.

Notice that this is not exclusive to React in any way. It's currently un-tested, but it should be possible to use with other libraries as well.

Development

The core of the application is an Express server with some middleware:

Install dependencies with Yarn:

$ yarn

This should install the ReasonML and BuckleScript platform to compile the code to JavaScript.