{"id":15388910,"url":"https://github.com/killercodemonkey/graphql-pub-sub-with-initial-value","last_synced_at":"2026-02-13T11:39:23.482Z","repository":{"id":37412446,"uuid":"192927298","full_name":"KillerCodeMonkey/graphql-pub-sub-with-initial-value","owner":"KillerCodeMonkey","description":"GraphQL PubSub with intial value handling","archived":false,"fork":false,"pushed_at":"2024-03-13T05:00:53.000Z","size":2023,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-14T16:24:01.919Z","etag":null,"topics":["apollo","apollo-server","graphql","pubsub","subscription"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/KillerCodeMonkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.MD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"PayPal.Me/bengtler"}},"created_at":"2019-06-20T13:42:51.000Z","updated_at":"2024-05-03T06:23:29.457Z","dependencies_parsed_at":"2024-05-03T06:22:57.887Z","dependency_job_id":"e9b51bbb-3ace-4590-9064-01747a6800c2","html_url":"https://github.com/KillerCodeMonkey/graphql-pub-sub-with-initial-value","commit_stats":{"total_commits":561,"total_committers":4,"mean_commits":140.25,"dds":0.4456327985739751,"last_synced_commit":"e47a01d65361fd190d89129b18da2fbdbd884351"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KillerCodeMonkey%2Fgraphql-pub-sub-with-initial-value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KillerCodeMonkey%2Fgraphql-pub-sub-with-initial-value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KillerCodeMonkey%2Fgraphql-pub-sub-with-initial-value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KillerCodeMonkey%2Fgraphql-pub-sub-with-initial-value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KillerCodeMonkey","download_url":"https://codeload.github.com/KillerCodeMonkey/graphql-pub-sub-with-initial-value/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245938228,"owners_count":20697008,"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","apollo-server","graphql","pubsub","subscription"],"created_at":"2024-10-01T14:58:35.584Z","updated_at":"2026-02-13T11:39:23.476Z","avatar_url":"https://github.com/KillerCodeMonkey.png","language":"TypeScript","readme":"# graphql-pub-sub-with-initial-value\n\n[![Build Status](https://github.com/KillerCodeMonkey/graphql-pub-sub-with-initial-value/workflows/CI/badge.svg)](https://github.com/KillerCodeMonkey/graphql-pub-sub-with-initial-value/actions/) [![codecov](https://codecov.io/gh/KillerCodeMonkey/datetime-periods/branch/master/graph/badge.svg)](https://codecov.io/gh/KillerCodeMonkey/graphql-pub-sub-with-initial-value)\n\nGraphQLPupSubWithIntialValue is a simple npm package that extends GraphQLPubSub with an `asyncIteratorWithInitialState` method. It lets you define an async function how to get the initial value.\n\nAdditionally it provides the possibilty to execute some cleanup work, when a client disconnects or the AsynIterator is closed. For that you can use the exported `withCancel` or the `pubSub.withCancel` function.\n\nFor more information checkout the [GraphQL-Subscriptions](https://github.com/apollographql/graphql-subscriptions)\n\n## Donate/Support\n\nIf you like my work, feel free to support it. Donations to the project are always welcomed :)\n\n\u003ca href=\"https://www.buymeacoffee.com/bengtler\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: auto !important;width: auto !important;\" \u003e\u003c/a\u003e\n\nPayPal: [PayPal.Me/bengtler](http://paypal.me/bengtler)\n\n### Installation\n\n`npm install graphql-pub-sub-with-initial-value` or `yarn add graphql-pub-sub-with-initial-value`\n\n\u003e This package has peerDependencies to `graphql` and `graphql-subscriptions`, which you have to install yourself.\n\n### Usage\n\n#### Easy \u0026 Simple\n\n```TS\nconst asyncInititalValueFn = () =\u003e {\n  // grab initial values somewhere else. Read from file, memory, 🤷\n  return Promise.resolve(['test'])\n}\n\nimport { PubSubWithIntialValue } from 'graphql-pub-sub-with-initial-value'\n\nconst pubSubWithInitialValue = new PubSubWithIntialValue()\n\nconst asyncIterator = pubSubWithInitialValue.asyncIteratorWithInitialValue\u003cstring[]\u003e('TOPIC', asyncInititalValueFn)\n\npubSubWithInitialValue.withCancel(asyncIterator, () =\u003e console.log('on close/disconnect'))\n// triggers cancel/disconnect\nasyncIterator.return()\n```\n\n#### In a resolver of subsciption (ApolloServer)\n\nIt is recommended to put the pubSub on the context object during the ApolloServer creation or use PubSubs in combination with datasources or create it in a seperated file to reuse the instance.\n\n```TS\nimport { GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql'\nimport { PubSubWithIntialValue } from 'graphql-pub-sub-with-initial-value'\n\nexport const subscription = new GraphQLObjectType({\n  fields: {\n    callings: {\n      resolve(payload) {\n        return payload\n      },\n      subscribe(_obj, _args, context: { pubSub: PubSubWithIntialValue }): AsyncIterable\u003cany\u003e {\n        return context.pubSub.asyncIteratorWithInitialValue\u003cstring[]\u003e(() =\u003e Promise.resolve(['test']))\n      },\n      type: GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLString)))\n    }\n  },\n  name: 'Subscription'\n})\n```\n\n","funding_links":["PayPal.Me/bengtler","https://www.buymeacoffee.com/bengtler","http://paypal.me/bengtler"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkillercodemonkey%2Fgraphql-pub-sub-with-initial-value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkillercodemonkey%2Fgraphql-pub-sub-with-initial-value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkillercodemonkey%2Fgraphql-pub-sub-with-initial-value/lists"}