{"id":15068321,"url":"https://github.com/codecommission/subscriptions-transport-sse","last_synced_at":"2025-04-10T16:33:33.919Z","repository":{"id":57374002,"uuid":"89476997","full_name":"CodeCommission/subscriptions-transport-sse","owner":"CodeCommission","description":"A Server-Side-Events (SSE) client + server for GraphQL subscriptions","archived":false,"fork":false,"pushed_at":"2018-06-22T08:33:25.000Z","size":112,"stargazers_count":67,"open_issues_count":5,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T11:37:35.081Z","etag":null,"topics":["apollo","client","graphql","server","server-side-events","subscriptions","transport"],"latest_commit_sha":null,"homepage":"https://github.com/MikeBild/graphql-subscriptions-sse-presence-list","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeCommission.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-26T12:14:34.000Z","updated_at":"2025-01-25T23:59:27.000Z","dependencies_parsed_at":"2022-09-17T16:01:01.253Z","dependency_job_id":null,"html_url":"https://github.com/CodeCommission/subscriptions-transport-sse","commit_stats":null,"previous_names":["mikebild/subscriptions-transport-sse"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCommission%2Fsubscriptions-transport-sse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCommission%2Fsubscriptions-transport-sse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCommission%2Fsubscriptions-transport-sse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCommission%2Fsubscriptions-transport-sse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeCommission","download_url":"https://codeload.github.com/CodeCommission/subscriptions-transport-sse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248252718,"owners_count":21072701,"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":["apollo","client","graphql","server","server-side-events","subscriptions","transport"],"created_at":"2024-09-25T01:34:04.318Z","updated_at":"2025-04-10T16:33:33.894Z","avatar_url":"https://github.com/CodeCommission.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# subscriptions-transport-sse\n\nA GraphQL Server-Side-Events (SSE) server and client to facilitate GraphQL subscriptions.\n\n\u003e That's an API compatible SSE transport implementation of [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws).\n\n## Example\n\n* [GraphQL subscriptions over Server-Side-Events](https://github.com/MikeBild/graphql-subscriptions-sse-presence-list)\n\n## Getting Started\n\n```bash\nUsing Yarn:\n$ yarn add subscriptions-transport-sse\n\nOr, using NPM:\n$ npm install --save subscriptions-transport-sse\n```\n\n### ExpressJS Server\n\nStarting with the server, create a new simple SubscriptionsManager, with a PubSub implementation:\n\n```javascript\nimport { SubscriptionManager, PubSub } from 'graphql-subscriptions'\n\nconst schema = {} // Replace with your GraphQL schema object\nconst pubsub = new PubSub()\n\nconst subscriptionManager = new SubscriptionManager({\n  schema,\n  pubsub\n})\n```\n\nNow, use your subscriptionManager, and create your SubscriptionServer:\n\n```javascript\nconst express = require('express')\nconst app = express()\nconst expressGraphQLSubscriptionsSSETransport = require('subscriptions-transport-sse')\n\nexpressGraphQLSubscriptionsSSETransport.SubscriptionServer({\n  onSubscribe: (msg, params) =\u003e Object.assign({}, params, { context: { loaders: loaders(), } }),\n  subscriptionManager: graphqlSubscriptions.subscriptionManager,\n}, {\n  express: app,\n  path: '/subscriptions',\n})\n\napp.listen(SERVICE_PORT, () =\u003e console.log(`Listen on ${SERVICE_PORT}`))\n```\n\n### Apollo Client (Browser)\n\nFor client side, we will use SubscriptionClient, and we also need to extend our network interface to use this transport for GraphQL subscriptions:\n\n```javascript\nimport { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-sse'\nconst httpClient = createNetworkInterface({uri: `https://my-graphql.example.com/graphql`})\nconst sseClient = new SubscriptionClient(`https://my-graphql.example.com/subscriptions`)\nconst apolloClient = new ApolloClient({networkInterface: addGraphQLSubscriptions(httpClient, sseClient)})\n```\n\nNow, when you want to use subscriptions in client side, use your ApolloClient instance, with subscribe or subscribeToMore (according to your apollo-client usage):\n\n```javascript\napolloClient.subscribeToMore({\n    document: gql`\n        subscription onNewItem {\n            newItemCreated {\n                id\n            }\n        }`,\n    variables: {},\n    updateQuery: (prev, {subscriptionData}) =\u003e {\n        return; // Modify your store and return new state with the new arrived data\n    }\n});\n```\n\n## API\n\n\u003e TBD, but compatible with [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws).\n\n## Issue Reporting\n\nIf you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public [GitHub issue tracker](https://github.com/MikeBild/subscriptions-transport-sse/issues).\n\n## License\n\nThis project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.\n\n## Thanks\n\nYou like this __subscriptions-transport-sse__ and you want to see what coming next? Follow me on Twitter [`@mikebild`](https://twitter.com/mikebild).\n\nEnjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecommission%2Fsubscriptions-transport-sse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodecommission%2Fsubscriptions-transport-sse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecommission%2Fsubscriptions-transport-sse/lists"}