{"name":"@n1ru4l/in-memory-live-query-store","version":"0.6.1","peerDependencies":{"graphql":"^15.4.0"},"dependencies":{"@graphql-tools/wrap":"^7.0.3","@n1ru4l/graphql-live-query":"0.7.1","@n1ru4l/push-pull-async-iterable-iterator":"^2.0.0"},"repository":{"type":"git","url":"git+https://github.com/n1ru4l/graphql-live-queries.git","directory":"packages/in-memory-live-query-store"},"homepage":"https://github.com/n1ru4l/graphql-live-queries#readme","keywords":["graphql","query","live","real-time"],"author":{"name":"n1ru4l","email":"laurinquast@googlemail.com"},"license":"MIT","main":"index.cjs.js","module":"index.esm.js","typings":"index.d.ts","typescript":{"definition":"index.d.ts"},"description":"[![npm version](https://img.shields.io/npm/v/@n1ru4l/in-memory-live-query-store.svg)](https://www.npmjs.com/package/@n1ru4l/in-memory-live-query-store) [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/in-memory-live-query-store.svg)](https://www.np","bugs":{"url":"https://github.com/n1ru4l/graphql-live-queries/issues"},"_id":"@n1ru4l/in-memory-live-query-store@0.6.1","_nodeVersion":"12.20.2","_npmVersion":"6.14.11","dist":{"integrity":"sha512-LX3kdwDeh7NAXCyYKEvD+ifqsPiyFraFgih/uZ76Mm/MtYXiXDeFOofT+G/5sWZ8W4KaLYzj+wpTaDqIKYiDFw==","shasum":"87abf15f4f24d0d093050c70a083a2ec7be1cf86","tarball":"http://registry-npm.ywwl.com/@n1ru4l/in-memory-live-query-store/download/@n1ru4l/in-memory-live-query-store-0.6.1.tgz","fileCount":18,"unpackedSize":104923,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgOKQ1CRA9TVsSAnZWagAAsyYQAIR+oGiUz44vJeQ0e/n1\n28jORcu5IkWun7IkSuPKtgPl67w1vQF+5aKQm5IcNRIWO7SBLrZ2A2P0kYyW\n5R0Ok/E9vpbJcnhwEiRLsLeMbzI+jE694gnn0Ia18pqEIOq1Gu5FgqJcJxg6\nFmK/pB+J3JxwK896RiYfTDk6ToPVmamh0DTaliJuGuxxC3m9ySXT2wTsndQ2\nAE54xZQzybqcU6SxU8/9sKs1I8Mk0znupsUZ8HeUxDt3HTzVhUu+rpRZhKZ6\nDxei5MMQtyYQ97t4n2tI7CtcKlsupYCwQc7C0w6U0eJXH/UMdRNj72h0G16i\neEdDbgKIHt+IUsr+lVZDD8bqvc6CDgk0rdJWi3YBaDndCaEKGtQ+Kkc733OZ\nipEPuRtcGBlHvs3Isw6mBt0hsOqOShe6yUSlUeZEuYcOvau2y9cA5IuJToXl\nOYTEwUbqQ14pygxaTYzOg9jJ4YAK2rHX9aLGf2g5S9nqfqAPd7OHcFAXsset\nGM1BDgojMNUpCUuB0vvfU4jJgzHVYXRV+nt9iGB/bmIrhfcYSqPcyDtoejM3\nK4/HCnNm4kl71EvdDRQ+KdEapBJuh1sq9SsAC8Qlg0ywlcRFxtOqYFMGuy84\nseZQmaxRRyV7y2E7xMrSoI07sXqDasg0OFvJafEgbW3rWKfa3YjsVA0Q4fH+\ns6Uh\r\n=GLf0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIErnOW+W2TIWqZeAF9jYLeMOsof93DCWMnVZmxDbMoppAiB9nxpyzVZdL7IpG41Xgo+ck5vt+H0f9IFLD7jpjJK0tg=="}],"size":12732,"noattachment":false,"key":"/@n1ru4l/in-memory-live-query-store/-/@n1ru4l/in-memory-live-query-store-0.6.1.tgz"},"_npmUser":{"name":"n1ru4l","email":"laurinquast@googlemail.com"},"directories":{},"maintainers":[{"name":"n1ru4l","email":"laurinquast@googlemail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/in-memory-live-query-store_0.6.1_1614324788521_0.25067004274080773"},"_hasShrinkwrap":false,"readme":"# @n1ru4l/in-memory-live-query-store\n\n[![npm version](https://img.shields.io/npm/v/@n1ru4l/in-memory-live-query-store.svg)](https://www.npmjs.com/package/@n1ru4l/in-memory-live-query-store) [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/in-memory-live-query-store.svg)](https://www.npmjs.com/package/@n1ru4l/in-memory-live-query-store)\n\nA GraphQL live query store that tracks, invalidates and re-executes registered operations. Drop in replacement for `graphql-js` `execute`. Add live query capabilities to your existing GraphQL schema.\n\nCheck out the [todo example server](https://github.com/n1ru4l/graphql-live-queries/blob/main/packages/todo-example/server/src/schema.ts) for a sample integration.\n\n## Install Instructions\n\n```bash\nyarn add -E @n1ru4l/in-memory-live-query-store\n```\n\n## API\n\n### `InMemoryLiveQueryStore`\n\nA `InMemoryLiveQueryStore` instance tracks, invalidates and re-executes registered live query operations.\n\nThe store will keep track of all root query field coordinates (e.g. `Query.todos`) and global resource identifiers (e.g. `Todo:1`). The store can than be notified to re-execute live query operations that select a given root query field or resource identifier by calling the `invalidate` method with the corresponding values.\n\nA resource identifier is composed out of the typename and the actual resolved id value separated by a colon, but can be customized. For ensuring that the store keeps track of all your query resources you should always select the `id` field on your object types. The store will only keep track of fields with the name `id` and the type `ID!` (`GraphQLNonNull(GraphQLID)`).\n\n```ts\nimport { InMemoryLiveQueryStore } from \"@n1ru4l/in-memory-live-query-store\";\nimport { parse, execute as executeImplementation } from \"graphql\";\nimport { schema } from \"./schema\";\n\nconst inMemoryLiveQueryStore = new InMemoryLiveQueryStore();\n\nconst rootValue = {\n  todos: [\n    {\n      id: \"1\",\n      content: \"Foo\",\n      isComplete: false,\n    },\n  ],\n};\n\nconst execute = inMemoryLiveQueryStore.makeExecute(executeImplementation);\n\nexecute({\n  schema, // make sure your schema has the GraphQLLiveDirective from @n1ru4l/graphql-live-query\n  operationDocument: parse(/* GraphQL */ `\n    query todosQuery @live {\n      todos {\n        id\n        content\n        isComplete\n      }\n    }\n  `),\n  rootValue: rootValue,\n  contextValue: {},\n  variableValues: null,\n  operationName: \"todosQuery\",\n}).then(async (result) => {\n  if (isAsyncIterable(result)) {\n    for (const value of result) {\n      console.log(value);\n    }\n  }\n});\n\n// Invalidate by resource identifier\nrootValue.todos[0].isComplete = true;\ninMemoryLiveQueryStore.invalidate(`Todo:1`);\n\n// Invalidate by root query field coordinate\nrootValue.todos.push({ id: \"2\", content: \"Baz\", isComplete: false });\ninMemoryLiveQueryStore.invalidate(`Query.todos`);\n```\n\nThe `execute` function returned from `InMemoryLiveQueryStore.makeExecute` is a drop-in replacement for the default `execute` function exported from `graphql-js`. You can provide your own `execute` function from any graphql-js version or other library.\n\nPass it to your favorite graphql transport that supports returning `AsyncIterableIterator` (or `AsyncGenerator`) from `execute` and thus delivering incremental query execution results.\n\nList of known and tested compatible transports/servers:\n\n| Package                                                                                                                          | Transport                   | Version                                                                                                                                                                         | Downloads                                                                                                                                                                          |\n| -------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [`@n1ru4l/socket-io-graphql-server`](https://github.com/n1ru4l/graphql-live-queries/blob/main/packages/socket-io-graphql-server) | WebSocket/HTTP Long Polling | [![npm version](https://badge.fury.io/js/%40n1ru4l%2Fsocket-io-graphql-server.svg)](https://github.com/n1ru4l/graphql-live-queries/blob/main/packages/socket-io-graphql-server) | [![npm downloads](https://img.shields.io/npm/dm/@n1ru4l/socket-io-graphql-server.svg)](https://github.com/n1ru4l/graphql-live-queries/blob/main/packages/socket-io-graphql-server) |\n| [`graphql-helix`](https://github.com/danielrearden/graphql-helix)                                                                | HTTP/SSE                    | [![npm version](https://badge.fury.io/js/graphql-helix.svg)](https://github.com/danielrearden/graphql-helix)                                                                    | [![npm downloads](https://img.shields.io/npm/dm/graphql-helix.svg)](https://github.com/danielrearden/graphql-helix)                                                                |\n| [`graphql-ws`](https://github.com/enisdenjo/graphql-ws)                                                                          | WebSocket                   | [![npm version](https://badge.fury.io/js/graphql-ws.svg)](https://github.com/enisdenjo/graphql-ws)                                                                              | [![npm downloads](https://img.shields.io/npm/dm/graphql-ws.svg)](https://github.com/enisdenjo/graphql-ws)                                                                          |\n\n## Recipes\n\n### Using with Redis\n\nYou can use Redis to synchronize invalidations across multiple instances.\n[A full runnable example can be found here](../example-redis).\n\n```ts\nimport Redis from \"ioredis\";\nimport { InMemoryLiveQueryStore } from \"@n1ru4l/in-memory-live-query-store\";\nimport { execute as defaultExecute } from \"graphql\";\n\nconst inMemoryLiveQueryStore = new InMemoryLiveQueryStore();\n\nconst client = new Redis(redisUri);\nconst subClient = new Redis(redisUri);\n\nclass RedisLiveQueryStore {\n  pub: Redis;\n  sub: Redis;\n  channel: string;\n  liveQueryStore: InMemoryLiveQueryStore;\n\n  constructor(\n    pub: Redis,\n    sub: Redis,\n    channel: string,\n    liveQueryStore: InMemoryLiveQueryStore\n  ) {\n    this.pub = pub;\n    this.sub = sub;\n    this.liveQueryStore = liveQueryStore;\n    this.channel = channel;\n\n    this.sub.subscribe(this.channel, (err) => {\n      if (err) throw err;\n    });\n\n    this.sub.on(\"message\", (channel, resourceIdentifier) => {\n      if (channel === this.channel && resourceIdentifier)\n        this.liveQueryStore.invalidate(resourceIdentifier);\n    });\n  }\n\n  async invalidate(identifiers: Array<string> | string) {\n    if (typeof identifiers === \"string\") {\n      identifiers = [identifiers];\n    }\n    for (const identifier of identifiers) {\n      this.pub.publish(this.channel, identifier);\n    }\n  }\n\n  makeExecute(execute: typeof defaultExecute) {\n    return this.liveQueryStore.makeExecute(execute);\n  }\n}\n\nconst liveQueryStore = new RedisLiveQueryStore(\n  client,\n  subClient,\n  \"live-query-invalidations\",\n  inMemoryLiveQueryStore\n);\n```\n","publish_time":1614324788702,"_cnpm_publish_time":1614324788702,"dist-tags":{"alpha":"0.11.0-alpha-20260720125639-14552d533a10d99fe5ade90b08c0facfad626bfe","latest":"0.11.0","rc":"0.11.0-rc-20260720130219-41f090c3809f65d64117b705343943e437843cda"}}