██████╗ ██████╗ █████╗ ██████╗ ██╗ ██╗ ██████╗ ██╗ ██████╗ ██╗ ██╗███╗ ██╗
██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║ ██║██╔═══██╗██║ ██╔════╝ ██║ ██║████╗ ██║
██║ ███╗██████╔╝███████║██████╔╝███████║██║ ██║██║ █████╗██║ ███╗██║ ██║██╔██╗ ██║
██║ ██║██╔══██╗██╔══██║██╔═══╝ ██╔══██║██║▄▄ ██║██║ ╚════╝██║ ██║██║ ██║██║╚██╗██║
╚██████╔╝██║ ██║██║ ██║██║ ██║ ██║╚██████╔╝███████╗ ╚██████╔╝╚██████╔╝██║ ╚████║
╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══▀▀═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝
Augmented query interface for the graph universal database http://gun.js.org/
npm install graphql-gun
With React
Say you want to attach offline first, realtime data to the Color component.
const gql = ;const Gun = ;const React = ;const ReactDOM = ;const gun = ;const createContainer graphqlGun = React gun; const Color = // data will be passed in by the container with all the data you asked for // component will also redraw when your subscriptions update <div style=color>JSON</div>
You can use a relay inspired high order component to decorate it with live data:
let ColorContainer = ;
...or if you prefer apollo client:
ColorContainer = Color;
Then just render like normal.
ReactDOM;
Without React
Not using react?
You can use graphqlGun
with a more traditional imperative approach:
const graphqlGun = ;const Gun = ;const gql = const gun = ; const fish = gun;fish;fish;const friends = fish;const dori = fishconst martin = fishconst nemo = fishdori;martin;nemo;friends;friends;friends; const myQuery = gql`{ fish { red { name } blue { _chain } friends(type: Set) { name favoriteColor } }}`; ;
and it will print...
fish: red: name: 'Frank' // the name you set on the red fish blue: _chain: <Gunchain> // reference to gun chain at blue node friends: name: 'Dori' favoriteColor: 'blue' name: 'Martin' favoriteColor: 'orange' name: 'Nemo' favoriteColor: 'gold'
Use the live directive to subscribe via an promise/iterator combo.
const myQuery = gql`{ fish { red @live { name } }}`; const next = ; console;
Will print...
fish: red: name: 'Frank' // the name you set on the red fish
Then try:
gun; console;
And you will get...
fish: red: name: 'bob' // the updated name
Take a look at the tests to learn more.
Credits
Special thanks to @amark for creating Gun and answering all my noob questions.
Shout out to @stubailo for putting up with my late night graphql-anywhere PRs.
Also a shout out to everyone on the Gun gitter chat for talking through things.