obsidian
server caching demo using deno
.
This demo is designed to demonstrate Obsidian server caching in a basic backend app.
It's set up so you can easily compare it to the functionality of oak_graphql
, which does essentially the same thing, but without caching. In fact, if you look through the code base of the Obsidian backend caching service, you'll find striking similarities between the two (as if they used it as a template 👀).
server.js
code is based on the README
in the oak_graphql
documentation:
https://github.com/aaronwlee/oak-graphql
video exampmle of setting up oak_graphql
in deno
:
https://www.youtube.com/watch?v=Rc_HhL55JZM&t=384s
obsidian
source code:
https://github.com/open-source-labs/obsidian
graphql
documentation (the library used to make GraphQL query requests):
https://graphql.org/graphql-js/graphql/#graphql
- Make necessary installs (use default everything):
redis: https://redis.io/docs/getting-started/installation/install-redis-on-mac-os/
deno: https://deno.land/manual/getting_started/installation
denon: https://deno.land/manual/getting_started/installation (make sure to add denon to your PATH: https://stackoverflow.com/questions/62057786/zsh-command-not-found-denon-even-after-installing-denon) - Toggle comments in
server.js
such that the import statements andGraphQLService
variable construction are both with respect to Obsidian (they should be by default) - In a terminal, start a redis server:
redis-server
- In a different terminal, run the denon start script:
denon start
- Open the graphQL sandbox -> go to "http://localhost:8000/graphql"
Note: the url to the sandbox is the same (by default) in bothobsidian
andoak_graphql
- look insrc/Obsidian.ts
in the Obsidian source code and you'll find that they import the playground fromoak_graphql
(implemented on line 153) - Make a request in the playground or postman (if you use postman, set the request type to POST and create the query as GraphQL data type):
Another quirk - you MUST include a fieldid
and a field__typename
in your request.__typename
is metadata in any GraphQL query.
query {
getUser {
id
firstName
__typename
}
}
- Check the cache for the query:
- launch the Redis CLI in a new terminal: type
redis-cli
- view all available keys in the cache:
KEYS *