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

reduxql

v0.0.1-pre2

Published

Use GraphQL to select from a Redux store

Downloads

5

Readme

ReduxQL

Proof of concept for using GraphQL to select data from a Redux store.

Under active development, but definitely not ready for production!

npm i --save [email protected]

Motivation

When using Redux, it is advisable to keep your reducers as "dumb" as possible by keeping the minimum amount of state in your store.

While rendering, we then have to transform this Redux store into props for our components. You probably use a library like react-redux or reselect to accomplish this.

This library allows us to declaratively define these "selectors" as a GraphQL schema over the Redux store to provide a more robust interface for handling local data.

Example

Support we have a local Redux store that contains data for a nested TodoList:

todos: {
  0: {
    tag: 'Weekend picnic',
    childTodoIds: ['1', '2'],
  },

  1: {
    tag: 'Make juice',
    childTodoIds: [],
  },

  2: {
    tag: 'Cut vegetables',
    childTodoIds: [],
  },

  rootIds: ['0'],
  expandedTodoIds: ['0'],
},

We need to transform our data so that our "dumb" components can render it. Wouldn't it be great if we could just use a GraphQL query to provide the data?

1. Define a Schema

const typeDefs = [`
  schema {
    query: RootQuery
  }

  type Todo {
    id: ID!
    tag: String
    children: [Todo]
  }

  type RootQuery {
    todos(): [Todos]!
  }
`];

const resolvers = {
  RootQuery: {
    todos(root, { id }, { state }) {
        // ...
    },
  },
  
  Todo: {
     children(root, { id }, { state }) {
        // ...
     }
  },
};

const schema = generateSchema({ typeDefs, resolvers });

2. Provide the schema to React components:

import { createStore } from 'redux';
import { Provider } from 'reduxql';

import reducer from './reducers';
import schema from './schema';

const store = createStore(reducer);
  
render(
  <Provider schema={schema} store={store}>
    <AppContainer />
  </Provider>,
  root,
);

3. Connect components to render data:

@connect({
  mapQueryToProps() {
    return {
      query: `{
        todos {
          id
          isExpanded
          tag
          children {
            id
            tag
          }
        }
      }`,
    };
  }
})(TodoList)

API

  • <Provider store schema>
  • connect({[mapQueryToProps], [mapDispatchToProps]})

Contributing

We will be using this in production at AppHub! Check out the issues for some fun things to do, or email [email protected] if you love developer tools and want to work on this stuff full-time!