在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):open-source-labs/obsidian开源软件地址(OpenSource Url):https://github.com/open-source-labs/obsidian开源编程语言(OpenSource Language):TypeScript 90.1%开源软件介绍(OpenSource Introduction):GraphQL, built for Deno.
Features
OverviewObsidian 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. InstallationQUICK START
Creating the Routerimport { 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,
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"]
});
// attach the graphql routers routes to our app
app.use(GraphQLRouter.routes(), GraphQLRouter.allowedMethods()); Creating the Wrapperimport { ObsidianWrapper } from 'https://deno.land/x/obsidian/clientMod.ts';
const App = () => {
return (
<ObsidianWrapper>
<MovieApp />
</ObsidianWrapper>
);
}; Making a Queryimport { useObsidian, BrowserCache } from 'https://deno.land/x/obsidian/clientMod.ts';
const MovieApp = () => {
const { query, cache, setCache } = 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))
.then(resp => setCache(new BrowserCache(cache.storage)))
}}
>Get Movies</button>
);
}; Making a Mutationimport { useObsidian, BrowserCache } from 'https://deno.land/x/obsidian/clientMod.ts';
const MovieApp = () => {
const { mutate, cache, setCache } = 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))
.then(resp => setCache(new BrowserCache(cache.storage)))
}}
>Get Movies</button>
);
} DocumentationDeveloper Toolinformation and instructions on how to use our developer tool can be found here Obsidian 5.0 Demogithub for a demo with some example code to play with: Dockerized Demoworking demo to install locally in docker: Working Example Demo Codegithub for a demo with some example code to play with: AuthorsYurii Shchyrba |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论