Code Monkey home page Code Monkey logo

obsidian's Introduction

Obsidian

GraphQL, built for Deno.

Obsidian Tweet

from Lascaux

GitHub GitHub issues GitHub last commit GitHub Repo stars

Features

  • GraphQL query abstraction and caching in SSR React projects, improving the performance of your app
  • Normalized caching, optimizing memory management to keep your site lightweight and fast
  • Fullstack integration, leveraging client-side and server-side caching to streamline your caching strategy

Overview

Obsidian is Deno's first native GraphQL caching client and server module. Boasting lightning-fast caching and fetching capabilities alongside headlining normalization and destructuring strategies, Obsidian is equipped to support scalable, highly performant applications.

Optimized for use in server-side rendered React apps built with Deno, full stack integration of Obsidian enables many of its most powerful features, including optimized caching exchanges between client and server and extremely lightweight client-side caching.

Documentation and Demo

obsidian.land

Installation

QUICK START

In the server:

import { ObsidianRouter } from 'https://deno.land/x/[email protected]/mod.ts';

In the app:

import { ObsidianWrapper } from 'https://deno.land/x/[email protected]/clientMod.ts';

Creating the Router

import { Application, Router } from 'https://deno.land/x/[email protected]/mod.ts';
import { ObsidianRouter, gql } from 'https://deno.land/x/[email protected]/mod.ts';

const PORT = 8000;

const app = new Application();

const types = (gql as any)`
  // Type definitions
`;

const resolvers = {
  // Resolvers
}

interface ObsRouter extends Router {
  obsidianSchema?: any;
}

const GraphQLRouter = await ObsidianRouter<ObsRouter>({
  Router,
  typeDefs: types,
  resolvers: resolvers,
  redisPort: 6379,
});

app.use(GraphQLRouter.routes(), GraphQLRouter.allowedMethods());

await app.listen({ port: PORT });

Sending ObsidianSchema

interface initialState {
  obsidianSchema?: any;
}

const initialState: initialState = {
  obsidianSchema: GraphQLRouter.obsidianSchema
}

const router = new Router();
router.get('/', handlePage);

function handlePage(ctx: any) {
  try {
    const body = (ReactDomServer as any).renderToString(<App />);
    ctx.response.body = `<!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="UTF-8">
        <title>SSR React App</title>
        <script>
          window.__INITIAL_STATE__ = ${JSON.stringify(initialState)};
        </script>
      </head>
      <body>
        <div id="root">${body}</div>
        <script src="/static/client.tsx" defer></script>
      </body>
      </html>`;
  } catch (error) {
    console.error(error);
  }
}

app.use(router.routes(), router.allowedMethods());

Creating the Wrapper

import { ObsidianWrapper } from 'https://deno.land/x/[email protected]/clientMod.ts';

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

Making a Query

import { useObsidian } from 'https://deno.land/x/[email protected]/clientMod.ts';

const WeatherApp = () => {
  const { gather } = useObsidian();
  const [weather, setWeather] = (React as any).useState('Sunny');

  return (
    <h1>{weather}</h1>
    <button
      onClick={() => {
        gather(`query { getWeather { id description } }`)
        .then(resp => setWeather(resp.data.getWeather.description))
      }}
    >Get Weather</button>
  );
};

Documentation

obsidian.land

Authors

Lascaux Engineers

Alonso Garza
Burak Caliskan
Matt Meigs
Travis Frank

obsidian's People

Contributors

alonsog66 avatar caliskanburak avatar michael-spengler avatar mmeigs avatar travismfrank avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.