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

olympus-cache

v1.0.3

Published

A hybrid caching library for GraphQL written for Javascript Express

Downloads

4

Readme

PRs Welcome Licence NPM Medium LinkedIn

Olympus is a hybrid caching library for GraphQL written for Javascript Express

Features

  • Automatically creates and caches GraphQL queries.
  • Integrates with any server running on Express/Node.js.
  • Includes caching with Redis and in the browser's local storage.

Check out our demo site to see what Olympus can do.


Table of Contents


Install Olympus

Install our Express library via npm

npm install olympus-cache

Set up your Express server

  1. Import our Redis Middleware
const RedisCache = require('olympus-server');
  1. Set up your Redis Server
const redis = require('redis');
const redisClient = redis.createClient({
    host: "localhost",
    port: 6379,
  });
redisClient.connect();
const redisInstance = new RedisCache(redisClient, '//insert url with /graphql endpoint here');

// REQUIRED
app.use(express.json())
app.use(express.urlencoded({ extended: true }));
  1. Add the following endpoints
app.use('/olympus', redisInstance.cacheResponse, (req, res) => {
    res.status(200).send(res.locals)
});
app.use('/graphql', graphqlHTTP({schema, graphiql: true}));
  1. Don't forget to run the command line 'redis-server' on the machine with your server

Making Queries

  1. Import Olympus in files that make GraphQL queries
import { Olympus } from 'olympus-fetch';
  1. Olympus is designed to make it easy to switch over from the Fetch API. All you have to do is replace the word fetch with the word Olympus. Remove the endpoint argument, and adjust the 'body' key inside the second arugment.

For example, here's how you might send a GraphQL request using the Fetch API:

fetch('/graphql', {
  method: 'POST',
  headers: { 'Content-Type': 'application/graphql' },
  body: // query string
})
.then(/* code */)

And here's what that same request looks like using Olympus:

Olympus({
  method: 'POST',
  headers: { 'Content-Type': 'application/graphql' },
  body: JSON.stringify({query: // query string})
})
.then(/* code */)

Simply replace fetch with Olympus wherever the client-side code queries the GraphQL API, and you're done! You've set up caching inside your client's browser Local Storage.

Making Mutations

In order to make a mutation, follow the same steps above. Simply replace fetch with Olympus wherever the client-side code makes mutations using the GraphQL API, and you're done! Simply enter your string containing the mutation inside of the key "query".

Olympus({
  method: 'POST',
  headers: { 'Content-Type': 'application/graphql' },
  body: JSON.stringify({query: // mutation string})
})
.then(/* code */)

The Team

Adam Lang | GitHub | LinkedIn Bryan Kim | GitHub | LinkedIn Kevin Le | GitHub | LinkedIn Marshall Kim | GitHub | LinkedIn

License

This product is licensed under the MIT License - see the LICENSE file for details.

This is an open source product.

This product is accelerated by OS Labs.