Obsidian
from Lascaux
Features
- (New!) Server-side cache invalidation only on affected entries
- (New!) Flexible cache responds with only data requested from selected fields
- (New!) Developer tool for Obsidian is now updated to Manifest version 3 and invalid Bootstrap module imports were also fixed along with CodeMirror dependencies
- GraphQL query abstraction and caching improving the performance of your app
- SSR React wrapper, allowing you to cache in browser
- Configurable caching options, giving you complete control over your cache
- Fullstack integration, leveraging client-side and server-side caching to streamline your caching strategy
- Support for the full GraphQL convention
- Support for client-side and server-side cache invalidation
- Optional GraphQL DoS attack mitigation security module
Overview
Obsidian is Deno’s first native GraphQL caching client and server module. Boasting lightning-fast caching and fetching capabilities alongside headlining normalization and rebuilding strategies, Obsidian is equipped to support scalable, highly performant applications.
With additional support for use in server-side rendered React apps built with Deno, full stack integration of Obsidian enables a fast and flexible caching solution.
Installation
Creating the Router
import { Application, Router } from 'https://deno.land/x/oak@v6.0.1/mod.ts';
import { ObsidianRouter, gql } from 'https://deno.land/x/obsidian/mod.ts';
import { resolvers } from './ import from your resolvers file';
import { types } from './ import your schema/types from schema/types file';
interface ObsRouter extends Router {
obsidianSchema?: any;
}
const GraphQLRouter =
(await ObsidianRouter) <
ObsRouter >
{
Router,
typeDefs: types,
resolvers: resolvers,
redisPort: 6379, //Desired redis port
useCache: true, //Boolean to toggle all cache functionality
usePlayground: true, //Boolean to allow for graphQL playground
useQueryCache: true, //Boolean to toogle full query cache
useRebuildCache: true, //Boolean to toggle rebuilding from normalized data
customIdentifier: ['id', '__typename'],
mutationTableMap = {}, //Object where keys are add mutation types and value is an array of affected tables (e.g. {addPlants: ['plants'], addMovie: ['movies']})
};
// attach the graphql routers routes to our app
app.use(GraphQLRouter.routes(), GraphQLRouter.allowedMethods());
Creating the Wrapper
import { ObsidianWrapper } from 'https://deno.land/x/obsidian/clientMod.ts';
const App = () => {
return (
<ObsidianWrapper>
<MovieApp />
</ObsidianWrapper>
);
};
Making a Query
import { useObsidian } from 'https://deno.land/x/obsidian/clientMod.ts';
const MovieApp = () => {
const { query } = useObsidian();
const [movies, setMovies] = (React as any).useState('');
const queryStr = `query {
movies {
id
title
releaseYear
genre
}
}
`;
return (
<h1>{movies}</h1>
<button
onClick={() => {
query(queryStr)
.then(resp => setMovies(resp.data))
}}
>Get Movies</button>
);
};
Making a Mutation
import { useObsidian } from 'https://deno.land/x/obsidian/clientMod.ts';
const MovieApp = () => {
const { mutate } = useObsidian();
const [movies, setMovies] = (React as any).useState('');
const queryStr = `mutation {
addMovie(input: {title: "Cruel Intentions", releaseYear: 1999, genre: "DRAMA" }) {
id
title
releaseYear
genre
}
}
`;
return (
<h1>{movies}</h1>
<button
onClick={() => {
mutate(queryStr)
.then(resp => setMovies(resp.data))
}}
>Get Movies</button>
);
}
Selecting LFU/LRU and capacity; default (if not provided) LFU, 2000
<ObsidianWrapper algo='LRU' capacity='5000'>
<Home />
</ObsidianWrapper>
Documentation
Developer Tool
Information and instructions on how to use our developer tool can be found here
works with Obsidian 5.0
oslabs-beta/obsidian-developer-tool
Obsidian 5.0 Demo
Github for a demo with some example code to play with:
oslabs-beta/obsidian-demo-5.0
Dockerized Demo
Working demo to install locally in docker:
oslabs-beta/obsidian-demo-docker
Features In Progress
- Ability to query the database for only those fields missing from the cache
- Developer Tool Settings component, fully functioning Playground component
Authors
Alex Lopez
Kevin Huang
Matthew Weisker
Ryan Ranjbaran
Derek Okuno
Liam Johnson
Josh Reed
Jonathan Fangon
Liam Jeon
Yurii Shchyrba
Linda Zhao
Ali Fay
Anthony Guan
Yasir Choudhury
Yogi Paturu
Michael Chin
Dana Flury
Sardor Akhmedov
Christopher Berry
Olivia Yeghiazarian
Michael Melville
John Wong
Kyung Lee
Justin McKay
Patrick Sullivan
Cameron Simmons
Raymond Ahn
Alonso Garza
Burak Caliskan
Matt Meigs
Travis Frank
Lourent Flores
Esma Sahraoui
Derek Miller
Eric Marcatoma
Spencer Stockton