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

redux-offline-apollo-link

v1.6.0

Published

A Wrapper Function to switch between using apollo client links and redux offline actions

Downloads

52

Readme

Redux Offline Apollo Link

NOTE This is still TBD. Use at your own risk!!

This is a close fork of apollo-upload-client, and acts as a drop in replacement.

I needed a way to get customized actions dispatched from apollo as network activity occured (request, success, failures).

This is closely tied with Redux Offline.

Redux Offline offers actions to be dispatched when a device is offline and go to a queue (aka outbox).

Read more about Redux Offline

Requirements

  • @redux-offline/redux-offline: ^2.0.0
  • apollo-client: ^2.4.8

Installation

import { ApolloClient } from "apollo-client";
import { reduxOfflineApolloLink } from "redux-offline-apollo-link";
import { store } from "../../store";

export const client = new ApolloClient({
  link: ApolloLink.from([
    reduxOfflineApolloLink(
      {
        uri: "http://your.graphql.server.com:3001/graphql"
      },
      store
    )
  ]),
  cache: new InMemoryCache()
});

Usage in Components

In order to use the redux actions, you need to provide a variables.[VARIABLE NAME] to your graphql higher order component call.

The only REQUIRED variable to date is actionType

Options

  • uri - The GraphQL URI
  • fetch - Description Needed
  • fetchOptions - Description Needed
  • credentials - Description Needed
  • headers - Description Needed
  • includeExtensions - Description Needed
  • globalErrorsCheck: An Optional function to be called whenever a graphql result contains errors. Callback function contains a result parameter, which contains 2 keys, errors and data
  • onCatchErrors: An Optional function to be called during a catch from the fetch call. Callback function contains a single error parameter which contains the Error

Variables

  • actionType REQUIRED - The name of the request action
  • actionCommitSuffix - Suffix of the action type when a success occurs Default: "COMMIT"
  • actionRollbackSuffix - Suffix of the action type when a rollback occurs Default: "ROLLBACK"
  • options - Suffix of the action type when a rollback occurs Default: "ROLLBACK" - payloadFormatter(payload) Optional Function to format the response coming back from GraphQL on a successful retrieval. payload is provided as a parameter. This function returns back the modified data. This is a good place to run data normalizations
    • errorsCheck(result) Optional Function to give the client the choice for whether it should throw an error if errors are present on GraphQL response. It throws an error by default if function is not provided. If you want to not call the _COMMIT or _ROLLBACK throw a new AbortEffectsError().
    • parseAndHandleHttpResponse(operation, result) Optional Function to give the client the choice for whether it should throw an error if there's an HTTP/GraphQL schema error present on GraphQL response. It throws an error by default if the function is not provided.
    • skipOffline Skips offline check returning error right away if connection can't be stablished.

Examples

graphql Query HoC Example

export default compose(
  graphql(
    gql`
      query uploads {
        uploads {
          id
          filename
          mimetype
          path
        }
      }
    `,
    {
      options: {
        variables: {
          actionType: "DEMO_QUERY",
          actionCommitSuffix: "COMMIT",
          actionRollbackSuffix: "ROLLBACK",
          options: {
            payloadFormatter(payload) {
              return doSomething({
                ...payload,
                extra: true
              });
            }
          }
        }
      }
    }
  ),
  connect(state => ({}))
)(DemoQuery);

graphql Mutation Example

export default compose(
  graphql(
    gql`
      mutation($file: Upload!) {
        singleUpload(file: $file) {
          id
          filename
          mimetype
          path
        }
      }
    `,
    {
      options: {
        variables: {
          actionType: "DEMO_MUTATION"
        }
      }
    }
  ),
  connect(state => ({
    images: state.images.images
  }))
)(Mutation);

Direct Client call Example

const { client } = this.props;
return client.query({
  query,
  fetchPolicy: "no-cache",
  variables: {
    startDateTimeUtc,
    endDateTimeUtc,
    actionType: "TODAY_SCHEDULES_REQUEST",
    options: {
      payloadFormatter(payload: any) {
        return payload;
      }
    }
  }
});