Olympus
A hybrid caching library for GraphQL written for Javascript Express
Install / Use
/learn @oslabs-beta/OlympusREADME
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
<a name="install"/> Install Olympus
Install our Express library via npm
npm install olympus-cache
<a name="server"/> Set up your Express server
- Import our Redis Middleware
const RedisCache = require('olympus-server');
- 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 }));
- Add the following endpoints
app.use('/olympus', redisInstance.cacheResponse, (req, res) => {
res.status(200).send(res.locals)
});
app.use('/graphql', graphqlHTTP({schema, graphiql: true}));
- Don't forget to run the command line 'redis-server' on the machine with your server
<a name="queries"/> Making Queries
- Import
Olympusin files that make GraphQL queries
import { Olympus } from 'olympus-fetch';
- Olympus is designed to make it easy to switch over from the Fetch API. All you have to do is replace the word
fetchwith the wordOlympus. 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.
<a name="mutations"/> 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 */)
<a name="team "/> The Team
Adam Lang | GitHub | LinkedIn <br> Bryan Kim | GitHub | LinkedIn <br> Kevin Le | GitHub | LinkedIn <br> Marshall Kim | GitHub | LinkedIn
<a name="license"/> 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.
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
84.7kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
99.6kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
