{"id":13647459,"url":"https://github.com/brysgo/graphql-gun","last_synced_at":"2025-04-06T03:07:49.018Z","repository":{"id":19100736,"uuid":"86029457","full_name":"brysgo/graphql-gun","owner":"brysgo","description":"A graphql API for the gun p2p graph database","archived":false,"fork":false,"pushed_at":"2023-01-06T01:46:11.000Z","size":995,"stargazers_count":406,"open_issues_count":24,"forks_count":24,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-04-14T19:49:47.128Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brysgo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-24T05:09:02.000Z","updated_at":"2024-01-26T08:18:13.000Z","dependencies_parsed_at":"2023-01-11T20:30:46.297Z","dependency_job_id":null,"html_url":"https://github.com/brysgo/graphql-gun","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brysgo%2Fgraphql-gun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brysgo%2Fgraphql-gun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brysgo%2Fgraphql-gun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brysgo%2Fgraphql-gun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brysgo","download_url":"https://codeload.github.com/brysgo/graphql-gun/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:03:34.563Z","updated_at":"2025-04-06T03:07:49.002Z","avatar_url":"https://github.com/brysgo.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"```\n██████╗ ██████╗  █████╗ ██████╗ ██╗  ██╗ ██████╗ ██╗            ██████╗ ██╗   ██╗███╗   ██╗\n██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║  ██║██╔═══██╗██║           ██╔════╝ ██║   ██║████╗  ██║\n██║  ███╗██████╔╝███████║██████╔╝███████║██║   ██║██║     █████╗██║  ███╗██║   ██║██╔██╗ ██║\n██║   ██║██╔══██╗██╔══██║██╔═══╝ ██╔══██║██║▄▄ ██║██║     ╚════╝██║   ██║██║   ██║██║╚██╗██║\n╚██████╔╝██║  ██║██║  ██║██║     ██║  ██║╚██████╔╝███████╗      ╚██████╔╝╚██████╔╝██║ ╚████║\n ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝  ╚═╝ ╚══▀▀═╝ ╚══════╝       ╚═════╝  ╚═════╝ ╚═╝  ╚═══╝\n```\n\n![Test](https://github.com/brysgo/graphql-gun/workflows/Test/badge.svg)\n\nAugmented query interface for the graph universal database http://gun.js.org/\n\n`npm install graphql-gun`\n\n## With React\n\nSay you want to attach offline first, realtime data to the Color component.\n```javascript\nconst gql = require(\"graphql-tag\");\nconst Gun = require(\"gun\");\nconst React = require(\"react\");\nconst ReactDOM = require(\"react-dom\");\nconst gun = Gun();\nconst { createContainer, graphqlGun } = require('graphql-gun/react')({React, gun});\n\nconst Color = ({color, data}) =\u003e (\n  // data will be passed in by the container with all the data you asked for\n  // component will also redraw when your subscriptions update\n  \u003cdiv style={{color}}\u003e{JSON.stringify(data, null, 2)}\u003c/div\u003e\n)\n```\n\nYou can use a relay inspired high order component to decorate it with live data:\n\n\n```javascript\nlet ColorContainer = createContainer(Color, {\n  fragments: {\n    data: gql`{\n      fish @live {\n        red {\n          name\n        }\n        \n        blue {\n          _chain\n        }\n        \n        friends(type: Set) {\n          name\n          favoriteColor\n        }\n      }\n    }`\n  }\n});\n```\n\n...or if you prefer apollo client:\n\n```javascript\nColorContainer = graphqlGun(gql`{\n  fish @live {\n    red {\n      name\n    }\n    \n    blue {\n      _chain\n    }\n    \n    friends(type: Set) {\n      name\n      favoriteColor\n    }\n  }\n}`)(Color);\n```\n\nThen just render like normal.\n\n```javascript\nReactDOM.render(\n  \u003cColorContainer color={'blue'} /\u003e,\n  document.getElementById('root')\n);\n\n```\n\n## Without React\n\nNot using react?\n\nYou can use `graphqlGun` with a more traditional imperative approach:\n\n```javascript\nconst graphqlGun = require('graphql-gun');\nconst Gun = require('gun');\nconst gql = require('graphql-tag')\n\nconst gun = Gun();\n\nconst fish = gun.get('fish');\nfish.put({red: {name: 'Frank'}});\nfish.put({blue: {name: 'John'}});\nconst friends = fish.get('friends');\nconst dori = fish.get('dori')\nconst martin = fish.get('martin')\nconst nemo = fish.get('nemo')\ndori.put({ name: 'Dori', favoriteColor: 'blue' });\nmartin.put({ name: 'Martin', favoriteColor: 'orange' });\nnemo.put({ name: 'Nemo', favoriteColor: 'gold' });\nfriends.set(dori);\nfriends.set(martin);\nfriends.set(nemo);\n\nconst myQuery = gql`{\n  fish {\n    red {\n      name\n    }\n    \n    blue {\n      _chain\n    }\n    \n    friends(type: Set) {\n      name\n      favoriteColor\n    }\n  }\n}`;\n\ngraphqlGun(myQuery, gun).then(function(results) {\n  console.log('results: ', results);\n});\n```\n\nand it will print...\n\n```javascript\n{\n  fish: {\n    red: {\n      name: 'Frank' // the name you set on the red fish\n    },\n    blue: {\n      _chain: \u003cGun.chain\u003e // reference to gun chain at blue node\n    },\n    friends: [\n      { name: 'Dori', favoriteColor: 'blue' },\n      { name: 'Martin', favoriteColor: 'orange' },\n      { name: 'Nemo', favoriteColor: 'gold' }\n    ]\n  }\n}\n```\n\nUse the live directive to subscribe via an promise/iterator combo.\n\n\n```javascript\nconst myQuery = gql`{\n  fish {\n    red @live {\n      name\n    }\n  }\n}`;\n\nconst { next } = graphqlGun(myQuery, gun);\n\nconsole.log(await next());\n```\n\nWill print...\n\n```javascript\n{\n  fish: {\n    red: {\n      name: 'Frank' // the name you set on the red fish\n    }\n  }\n}\n```\n\nThen try:\n\n```javascript\ngun.get('fish').get('red').put({name: 'bob'});\n\nconsole.log(await next());\n```\n\nAnd you will get...\n\n```javascript\n{\n  fish: {\n    red: {\n      name: 'bob' // the updated name\n    }\n  }\n}\n```\n\nTake a look at the tests to learn more.\n\n\n## Credits\n\nSpecial thanks to [@amark](https://github.com/amark/) for creating [Gun](https://github.com/amark/gun) and answering all my noob questions.\n\nShout out to [@stubailo](https://github.com/stubailo/) for putting up with my late night [graphql-anywhere](https://github.com/amark/) PRs.\n\nAlso a shout out to everyone on the Gun [gitter](https://gitter.im/amark/gun) chat for talking through things.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrysgo%2Fgraphql-gun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrysgo%2Fgraphql-gun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrysgo%2Fgraphql-gun/lists"}