{"name":"@n1ru4l/in-memory-live-query-store","version":"0.9.0-alpha-e02cfcd.0","peerDependencies":{"graphql":"^15.4.0 || ^16.0.0"},"dependencies":{"@graphql-tools/utils":"^8.5.2","@n1ru4l/graphql-live-query":"0.9.0","@repeaterjs/repeater":"^3.0.4"},"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.js","module":"esm/index.js","typings":"index.d.ts","typescript":{"definition":"index.d.ts"},"exports":{".":{"require":"./index.js","import":"./esm/index.js"},"./*":{"require":"./*.js","import":"./esm/*.js"}},"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\n```ts\nimport Redis from \"ioredis\";\nimport {\n  InMemoryLiveQueryStore,\n  InMemoryLiveQueryStoreParameter,\n} from \"@n1ru4l/in-memory-live-query-store\";\nimport { ExecutionArgs, execute as defaultExecute } from \"graphql\";\n\nconst CHANNEL = \"LIVE_QUERY_INVALIDATIONS\";\n\nexport class RedisLiveQueryStore {\n  pub: Redis.Redis;\n  sub: Redis.Redis;\n  liveQueryStore: InMemoryLiveQueryStore;\n\n  constructor(redisUrl: string, parameter?: InMemoryLiveQueryStoreParameter) {\n    this.pub = new Redis(redisUrl);\n    this.sub = new Redis(redisUrl);\n    this.liveQueryStore = new InMemoryLiveQueryStore(parameter);\n\n    this.sub.subscribe(CHANNEL, (err) => {\n      if (err) throw err;\n    });\n\n    this.sub.on(\"message\", (channel, resourceIdentifier) => {\n      if (channel === 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(CHANNEL, identifier);\n    }\n  }\n\n  makeExecute(execute: typeof defaultExecute) {\n    return this.liveQueryStore.makeExecute(args);\n  }\n}\n```\n","readmeFilename":"README.md","gitHead":"e02cfcda29c7e969d9bbfaa6b497c9a9db13fb67","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.9.0-alpha-e02cfcd.0","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-TMHWAT47/7qeze3Cd1xntdp+JVmtZl++esjRx3YSgaTw0tkxdKQUzQd9NO822KRZ+2kYDQoZMN/oyZ04LSROqg==","shasum":"3109084d6efd8f9d089cf31ce242b6bbc04baa50","tarball":"http://registry-npm.ywwl.com/@n1ru4l/in-memory-live-query-store/download/@n1ru4l/in-memory-live-query-store-0.9.0-alpha-e02cfcd.0.tgz","fileCount":19,"unpackedSize":46199,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhyG7fCRA9TVsSAnZWagAAda8P/21m1us79hW3/Ust7DGI\nre7yR1DRES8StJ2I/y0GMzPEZkR40/YNCNNHfiBmDJ1m+WpLCCf+ip91UxUD\n+06UMKlGQF/kE/qHu9A67hamhkwOS5K4hMJGKyeyG8OGe3gEzxnQjkgld4Vp\nTVPFCPfgLXsazmqwQFAKIjlt+ATn7CdUWkHvhLGBoFRnaPOkMSxlbycu1rEO\nxXIRR47GRsmzmAeNkcENFkjzw4SkEFo1s1LxKiRDETN9mfsPmEff5V0aU1f9\nthHgRG5zsavmUUaxO479VnFUhnlTW1jtyVVzv01QdvgsjUkL+ZgiTRS3wp/z\n5RXSRPWtjKl9GXIYrrwy5TplzhP+z7heTSpWiv3Ixrosz/BNwUWNJZ+/UIcR\nplgyfsDcB8yaN0oZtioY7FKneDkC/xHWvdued9MJMhXf3HCbNYFoed1F8pOY\nM2ykuuyk8Pf0dJSn0mUkMfPvPHdVtArtU/2ZNoZToSqhRAnhPK2KwRP4ggmv\nt+1V+bKh1jZaNSAQONS68Z4InDynSUTrQF2BixaeQw/jVJORTfyLjWBIRK7i\nYkwQX0204lz1tAbh7ck3ocALnt438gu3yy3LZUpOsLWVFTb8TrIQOTPl2ukK\nzL7tkTq1xNqhrnBbQJRtVcgA/HBydyftrQN5XnkIdoY3RToiC0erxm+TYdrG\nFC7T\r\n=xEtL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH5Xm4IJwBNEUtA0oEAWMj0dM0Kq1q5SSGmeIFdMghpSAiAnKM4xfCDxbIOMZkCKodJMKbwo7w5bxsSUgBZnfAvXFw=="}],"size":8322,"noattachment":false,"key":"/@n1ru4l/in-memory-live-query-store/-/@n1ru4l/in-memory-live-query-store-0.9.0-alpha-e02cfcd.0.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.9.0-alpha-e02cfcd.0_1640525534855_0.9519857336615076"},"_hasShrinkwrap":false,"publish_time":1640525535029,"_cnpm_publish_time":1640525535029,"dist-tags":{"alpha":"0.11.0-alpha-20260720125639-14552d533a10d99fe5ade90b08c0facfad626bfe","latest":"0.11.0","rc":"0.11.0-rc-20260720130219-41f090c3809f65d64117b705343943e437843cda"}}