From 80a8024ede14413fb28658ca0a1dea2ef6c2662d Mon Sep 17 00:00:00 2001 From: sdev-buildz <310740165+sdev-buildz@users.noreply.github.com> Date: Wed, 9 Sep 2026 00:18:22 +0530 Subject: [PATCH 1/2] docs(Code page): add 'graphql-shared-ws' javascript client library --- .../javascript/client/graphql-shared-ws.md | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/code/language-support/javascript/client/graphql-shared-ws.md diff --git a/src/code/language-support/javascript/client/graphql-shared-ws.md b/src/code/language-support/javascript/client/graphql-shared-ws.md new file mode 100644 index 0000000000..b1adde602b --- /dev/null +++ b/src/code/language-support/javascript/client/graphql-shared-ws.md @@ -0,0 +1,60 @@ +--- +name: GraphQL-Shared-WS +description: GraphQL clients sharing a single WebSocket connection across browsing contexts such as browser tabs, windows, iframes, etc... GraphQL subscriptions are indexed by their payloads, preventing duplicate subscription channels. +github: sdev-buildz/graphql-shared-ws +npm: graphql-shared-ws +tags: + - tools-and-libraries + - frontend +--- + +## ⚡ Optimizations +
+
+ +### 📦 SharedWorker size + +- The SharedWorker script is 📦 bundled, 🌳 tree-shaken, 📉 minified, 🗜️ gzipped, 🔠 base64 encoded and 📥 inlined within this library. +- All the SharedWorker registration logic (including decoding and decompression) are automatically handled by and within this library itself. +- The base64-encoded SharedWorker script is only 6 KB. ([generated source](https://github.com/sdev-buildz/graphql-shared-ws/blob/782d08e34387684846988a6eee132917f5357cef/src/util/worker-registration/tracked-generated/shared-worker-inline.ts)). + +
+ +### 🗂️ Subscription indexing + +- GraphQL subscriptions are indexed by their payloads across browsing contexts (across browser tabs, windows, iframes, etc...). +- When a user opens multiple tabs, network load remains identical to having just a single tab open. +- Making duplicate subscriptions across different UI components will not trigger extra network requests. + +
+ +## 🚀 Initialize and subscribe + +```ts +import { createSharedClient } from 'graphql-shared-ws' + +// create a client. +const sharedClient = createSharedClient({ + url: 'wss://example.com/api/graphql', +}) + +// make a graphql subscription +sharedClient.subscribe( + { + query: ` + subscription listenToMessages { + messageBroadcasted + } + `, + }, + { + next: (n) => { + console.log(`Last broadcasted message =`, n.data.messageBroadcasted) + }, + complete: () => { + console.log('subscription closed.') + }, + error: console.error, + } +) +``` From ab3df49514f3863a5d95f3e70adbbf60ef1e85b5 Mon Sep 17 00:00:00 2001 From: sdev-buildz <310740165+sdev-buildz@users.noreply.github.com> Date: Tue, 15 Sep 2026 20:30:41 +0530 Subject: [PATCH 2/2] chore(prettier): run 'prettier --write' to fix formatting --- .../javascript/client/graphql-shared-ws.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/code/language-support/javascript/client/graphql-shared-ws.md b/src/code/language-support/javascript/client/graphql-shared-ws.md index b1adde602b..781b19b7cd 100644 --- a/src/code/language-support/javascript/client/graphql-shared-ws.md +++ b/src/code/language-support/javascript/client/graphql-shared-ws.md @@ -8,7 +8,8 @@ tags: - frontend --- -## ⚡ Optimizations +## ⚡ Optimizations +

@@ -31,11 +32,11 @@ tags: ## 🚀 Initialize and subscribe ```ts -import { createSharedClient } from 'graphql-shared-ws' +import { createSharedClient } from "graphql-shared-ws" // create a client. const sharedClient = createSharedClient({ - url: 'wss://example.com/api/graphql', + url: "wss://example.com/api/graphql", }) // make a graphql subscription @@ -48,13 +49,13 @@ sharedClient.subscribe( `, }, { - next: (n) => { + next: n => { console.log(`Last broadcasted message =`, n.data.messageBroadcasted) }, complete: () => { - console.log('subscription closed.') + console.log("subscription closed.") }, error: console.error, - } + }, ) ```