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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bs-reason-apollo

v1.0.0-beta.4

Published

React Apollo bindings for BS

Readme

bs-reason-apollo

Build Status

Initially inspired by https://github.com/FormidableLabs/seattlejsconf-app/blob/master/re/types/ReactApollo.re But now with a more sugared usage with function as child.

Difference from reason-apollo official

This allows you to use a React Apollo Client that you already have in JS so you can gradually change to Reason. Setup the same way you would do for React Apollo and just plug it in.

Install

yarn add bs-reason-apollo

Update your bs-config.json

  "bs-dependencies": ["reason-react", "bs-reform", "bs-reason-apollo"],

ReactApollo.CreateWrapper

As you have your ApolloProvider somewhere in the top of your React JS tree you are already covered there. So now to use it with Apollo create a query definition module for you query:

/* re/SignInQueryGql.re */
open BsReasonApollo;

let query = GraphQLTag.gql({|
  query SignInQuery {
    currentUser {
      id
      email
    }
  }
|});

module Types = {
  type user = {. "id": string, "email": string};
  type error = {. "message": string};
  /* You must always have this data type with loading and error, it's what the HOC gives you */
  type data = {
    .
    "loading": Js.boolean,
    "error": Js.null_undefined(error),
    /* Our response */
    "currentUser": Js.null_undefined(user)
  };
};

type data = Types.data;

/* Define any Js.t variables that you query need here, if you don't use just declare it */
type variables;

type response = Types.user;

Now in your actually component:

open BsReasonApollo;

module SignInQueryWrapper = ReactApollo.CreateWrapper(SignInQueryGql);

...
let make = (_children) => {
  ...,
  render: (_self) =>
    <SignInQueryWrapper>
    ...((~data) =>
        switch (
          Js.to_bool(data##loading),
          Js.Null_undefined.to_opt(data##error),
          Js.Null_undefined.to_opt(data##currentUser)
        ) {
        | (true, _, _) => <FullLoading />
        | (false, _, Some(user)) =>
          <Welcome user />
        | (false, Some(error), _) => <Whoops name=error##message />
        | (false, None, _) =>
          <KeyboardAwareScrollView>
            <Wrapper>
              <Header>
                <Logo
                  source=Image.(
                           Required(Packager.require("../../../src/public/img/logo-calendar.png"))
                         )
                />
              </Header>
              <ContentWrapper
                contentContainerStyle=Style.(
                                        style([
                                          paddingVertical(Pt(40.)),
                                          justifyContent(SpaceAround)
                                        ])
                                      )>
                <SignInForm />
              </ContentWrapper>
            </Wrapper>
          </KeyboardAwareScrollView>
        }
      )
    </SignInQueryWrapper>
}

ReactApollo.CreateMutationWrapper

Define the mutation module:

/* re/SignInMutationGql.re */
open BsReasonApollo;

let query = GraphQLTag.gql({|
  mutation SignInQuery($input: SignInInput!) {
    signIn(input: $input) {
      error
      token
    }
  }
|});

module Types = {
  type input = {. "password": string, "email": string};
  type signIn = {. "error": Js.null_undefined(string), "token": Js.null_undefined(string)};
};

/* Needed for mutations, it'll be probably `variables` in the next release */
type input = Types.input;

/* Mutation response */
type response = {. "signIn": Types.signIn};
open BsReasonApollo;

/* Mutation wrapper */
module SignInMutationWrapper = ReactApollo.CreateMutationWrapper(SignInQueryGql);

/* https://github.com/Astrocoders/reform */
module SignInForm = ReForm.Create(SignInFormParams);

let convertInputToJs: SignInFormParams.state => SignInMutationGql.Types.signInInput =
  (values) => {"password": values.password, "email": values.email};

let handleSubmit = (mutate, values, setSubmitting) =>
  values
  |> convertToJs
  |> mutate
  |> Js.Promise.(
       then_(
         (payload) =>
           (
             switch (Js.Null_undefined.to_opt(payload##signIn##error)) {
             | Some(error) =>
               Alert.alert(~title="Something went wrong", ~message=error, ());
               setSubmitting(false)
             | None =>
               RouterActions.home(~actionType=`replace);
               let _ =
                 Utils.UserSession.setToken(
                   Utils.get(Js.Null_undefined.to_opt(payload##signIn##token), "")
                 );
               ignore()
             }
           )
           |> resolve
       )
     )
  |> ignore;

/* A little abstraction to make function as child composition hurt a bit less */
let enhanced = (mapper) => {
  <SignInMutationWrapper>
    ...((~mutate) => (
      <SignInForm
        initialValues={etc}
         onSubmit=(
           (values, ~setSubmitting, ~setError as _) =>
             handleSubmit(mutate, values, setSubmitting)
         )
      >
        ...mapper
      </SignInForm>
    ))
  </SignInMutationWrapper>
};

let component =

Demo

WIP