• Stars
    star
    751
  • Rank 60,419 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GraphQL, built for Deno - a native GraphQL caching client and server module

Obsidian

GraphQL, built for Deno.

Obsidian Tweet

GitHub GitHub issues GitHub last commit GitHub Repo stars

Features

  • (New!) Support for W-TinyLFU client-side cache that brings great hit-ratio performance with minimal memory overhead
  • (New!) Option to provide Obsidian with the search types your application uses, allowing data cached from complete dataset pulls to be accessible later on in searches for individual items
  • (New!) Refactored server-side caching with Redis
  • (New!) Rebuilt developer tool for Obsidian 8.0 for testing and analytics related to the new client caching options
  • (New!) Option for persistent queries, allowing only a smaller hash to be sent to the server on client-side cache misses, minimizing the cost of queries. Note that while this will increase the overall performance for frequent, repeat queries.
  • Flexible cache responds only with data requested from selected fields
  • 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

QUICK START

Creating the Router

import { Application, Router } from 'https://deno.land/x/[email protected]/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, // your router in deno
    typeDefs: types, // graphQL typeDefs
    resolvers: resolvers, // graphQL resolvers
  };

// attach the graphql router's routes to your deno app
app.use(GraphQLRouter.routes(), GraphQLRouter.allowedMethods());

Selecting options for the Router

const GraphQLRouter =
  (await ObsidianRouter) <
  ObsRouter >
  {
    Router, // Router that is initialized by server.
    path: '/graphql', // endpoint for graphQL queries, default to '/graphql'
    typeDefs: types, // graphQL typeDefs
    resolvers: resolvers, // graphQL resolvers
    usePlayground: true, // Boolean to allow for graphQL playground, default to false
    useCache: true, // Boolean to toggle all cache functionality, default to true
    redisPort: 6379, // Desired redis port, default to 6379
    policy: 'allkeys-lru', // Option select your Redis policy, default to allkeys-lru
    maxmemory: '2000mb', // Option to select Redis capacity, default to 2000mb
    searchTerms: [] //Optional array to allow broad queries to store according to search fields so individual searches are found in cache
    persistQueries: true, //Boolean to toggle the use of persistent queries, default to false - NOTE: if using, must also be enabled in client wrapper
    hashTableSize: 16, // Size of hash table for persistent queries, default to 16
    maxQueryDepth: 0, // Maximum depth of query, default to 0
    customIdentifier: ['__typename', '_id'], // keys to be used to idedntify and normalize object
    mutationTableMap: {}, //Object where keys are add mutation types and value is an array of affected tables (e.g. {addPlants: ['plants'], addMovie: ['movies']})
  };

Creating the Wrapper

import { ObsidianWrapper } from 'https://deno.land/x/obsidian/clientMod.ts';

const App = () => {
  return (
    <ObsidianWrapper>
      <MovieApp />
    </ObsidianWrapper>
  );
};

Selecting options for the Wrapper

<ObsidianWrapper 
  useCache={true} // Boolean indicating whether to use client-side cache, default to true
  algo='LRU' // String indicating cache policy to use for client-side cache, default to LFU. OTHER OPTIONS: W-Tiny-LFU, LRU
  capacity='5000' // String indicating numeric capacity of cache, default to 2000
  persistQueries={true} // Boolean indicating wheter to use persistent queries, default to false
  searchTerms={['title', 'director', 'genre']} // Optional parameter to set search terms of the data
>
  <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>
  );
}

Setting up Redis

In order to utilize server side caching, a Redis instance must be available and running. Redis installation and quick-start documentation can be found here. Make sure to keep a redis instance running whenever the application is utilizing server side caching to avoid running into issues.

To connect Obsidian to Redis, create a .env file in the root directory of the application with the following information:

REDIS_HOST= //string of redis host name, typically defaulted to '127.0.0.1' by Redis

Be sure to also specify the Redis TCP port by passing in the port number as an argument into Obsidian Router (see Selecting options for the Router above).

Documentation

getobsidian.io

Developer Tool

Information and instructions on how to use our developer tool can be found here
works with Obsidian 8.0
open-source-labs/obsidian-developer-tool

Obsidian 8.0 Demo

Github for a demo with some example code to play with:
oslabs-beta/obsidian-demo-8.0

Features In Progress

  • Server-side caching improvements
  • More comprehensive mutation support
  • searchTerms option optimization
  • Ability to store/read only the whole query
  • Hill Climber optimization for W-TinyLFU cache size allocation
  • Developer Tool server-side cache integration
  • Developer Tool View Cache component, and Playground component

Authors

David Kim
David Norman
Eileen Cho
Joan Manto
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

More Repositories

1

Svelvet

🎛 A Svelte library for building dynamic, infinitely customizable node-based user interfaces and flowcharts
Svelte
2,540
star
2

OverVue

Prototyping Tool For Vue Devs 适用于Vue的原型工具
Vue
2,463
star
3

Reactime

Developer tool for time travel debugging and performance monitoring in React applications.
TypeScript
2,165
star
4

PreVue

🎨 All in One Prototyping Tool For Vue Developers.
Vue
1,389
star
5

Spearmint

Testing, simplified. || An inclusive, accessibility-first GUI for generating clean, semantic Javascript tests in only a few clicks of a button.
TypeScript
1,289
star
6

SvelteStorm

SvelteStorm is an open-source IDE with a built-in Debugging window for viewing and debugging your Svelte project in real-time
Svelte
1,007
star
7

Swell

Swell: API development tool that enables developers to test endpoints served over streaming technologies including Server-Sent Events (SSE), WebSockets, HTTP2, GraphQL, gRPC, and tRPC..
JavaScript
980
star
8

Docketeer

A Docker & Kubernetes developer tool to manage containers & visualize both cluster and container metrics
TypeScript
862
star
9

Chronos

📊 📊 📊 Monitors the health and web traffic of servers, microservices, Kubernetes/Kafka clusters, containers, and AWS services with real-time data monitoring and receive automated notifications over Slack or email.
TypeScript
829
star
10

Recoilize

A Chrome Dev tool for debugging applications built with the experimental Recoil.js state management library.
TypeScript
604
star
11

SeeQR

A database analytic tool that allows developers to compare the efficiency of different schemas and queries on a granular level to make better informed architectural decisions regarding SQL databases at various scales.
TypeScript
594
star
12

Quell

Quell is an easy-to-use, lightweight JavaScript library providing a client- and server-side caching solution for GraphQL. Use Quell to prevent redundant client-side API requests and to minimize costly server-side response latency.
TypeScript
578
star
13

vno

a build tool for compiling and bundling Vue single-file components
TypeScript
432
star
14

ReacType

Prototyping Tool for exporting React/Typescript Applications!
TypeScript
429
star
15

Chromogen

UI-driven Jest test-generation package for Recoil selectors and Zustand store hooks
TypeScript
280
star
16

dbSpy

Visualize, modify, and build your database with dbSpy! An open-source data modeling tool to facilitate relational database development.
TypeScript
263
star
17

DenoGres

Deno + PostgreSQL = DenoGres
TypeScript
212
star
18

obsidian-developer-tool

Developer tool for monitoring client cache performance for Obsidian 8.0
TypeScript
49
star
19

SeeQR-Web

A web-based database analytic tool that allows a developer to compare the efficiency of different queries on a granular level to make better informed architectural decisions regarding Postgres databases at various scales.
TypeScript
15
star
20

Sveltestorm-Website

SvelteStorm website
Svelte
10
star
21

QuellDemo

Demo for Quell written in React utilizing Material UI, chartJS, redis, and graphQL.
TypeScript
7
star
22

reactime-web

Web page for Reactime
JavaScript
6
star
23

Reactype-web

This is the ReacType Website created with Next.js and Typescript
TypeScript
5
star
24

SeeQR-Website

SeeQR's Website
TypeScript
3
star