Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/open-source-labs/obsidian

GraphQL, built for Deno - a native GraphQL caching client and server module
https://github.com/open-source-labs/obsidian

deno graphql javascript typescript

Last synced: 7 days ago
JSON representation

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

Awesome Lists containing this project

README

        

![Obsidian](./assets/bannerfull_gradient.png)

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

```javascript
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
```javascript
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

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

const App = () => {
return (



);
};
```

## Selecting options for the Wrapper

```javascript

```

## Making a Query

```javascript
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 (

{movies}


{
query(queryStr)
.then(resp => setMovies(resp.data))
}}
>Get Movies
);
};
```

## Making a Mutation

```javascript
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 (

{movies}


{
mutate(queryStr)
.then(resp => setMovies(resp.data))
}}
>Get Movies
);
}
```
## 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](https://redis.io/docs/getting-started/). 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:

```javascript
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](http://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](https://github.com/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](https://github.com/oslabs-beta/obsidian-8.0-demo)

## 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](https://github.com/davidtoyoukim)
[David Norman](https://github.com/DavidMNorman)
[Eileen Cho](https://github.com/exlxxn)
[Joan Manto](https://github.com/JoanManto)
[Alex Lopez](https://github.com/AlexLopez7)
[Kevin Huang](https://github.com/kevin-06-huang)
[Matthew Weisker](https://github.com/mweisker)
[Ryan Ranjbaran](https://github.com/ranjrover)
[Derek Okuno](https://github.com/okunod)
[Liam Johnson](https://github.com/liamdimitri)
[Josh Reed](https://github.com/joshreed104)
[Jonathan Fangon](https://github.com/jonathanfangon)
[Liam Jeon](https://github.com/laj52)
[Yurii Shchyrba](https://github.com/YuriiShchyrba)
[Linda Zhao](https://github.com/lzhao15)
[Ali Fay](https://github.com/ali-fay)
[Anthony Guan](https://github.com/guananthony)
[Yasir Choudhury](https://github.com/Yasir-Choudhury)
[Yogi Paturu](https://github.com/YogiPaturu)
[Michael Chin](https://github.com/mikechin37)
[Dana Flury](https://github.com/dmflury)
[Sardor Akhmedov](https://github.com/sarkamedo)
[Christopher Berry](https://github.com/cjamesb)
[Olivia Yeghiazarian](https://github.com/Olivia-code)
[Michael Melville](https://github.com/meekle)
[John Wong](https://github.com/johnwongfc)
[Kyung Lee](https://github.com/kyunglee1)
[Justin McKay](https://github.com/justinwmckay)
[Patrick Sullivan](https://github.com/pjmsullivan)
[Cameron Simmons](https://github.com/cssim22)
[Raymond Ahn](https://github.com/raymondcodes)
[Alonso Garza](https://github.com/Alonsog66)
[Burak Caliskan](https://github.com/CaliskanBurak)
[Matt Meigs](https://github.com/mmeigs)
[Travis Frank](https://github.com/TravisFrankMTG/)
[Lourent Flores](https://github.com/lourentflores)
[Esma Sahraoui](https://github.com/EsmaShr)
[Derek Miller](https://github.com/dsymiller)
[Eric Marcatoma](https://github.com/ericmarc159)
[Spencer Stockton](https://github.com/tonstock)