{"name":"@n1ru4l/in-memory-live-query-store","version":"0.9.0-alpha-3ba5599.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":"3ba559940ff51ecfa6dcb1a0b7cfcf1de1c63be8","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-3ba5599.0","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-udIz9R1+NgkMQ28HYkePv26eDCymlOvvIVCib+PZf2R7oI3VJbczGi9y5L+H8xqWqyNwLvItn6Lz3Dby+QAq9w==","shasum":"97fb8805c5c7efb6f3edf9ac8360a23d3df9df65","tarball":"http://registry-npm.ywwl.com/@n1ru4l/in-memory-live-query-store/download/@n1ru4l/in-memory-live-query-store-0.9.0-alpha-3ba5599.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\nwsFcBAEBCAAQBQJhyG53CRA9TVsSAnZWagAAGZ4P/A4gwVlDiHfEgtFRXsne\nq5uNIQanVweg7Ot37nfmSHLPro6BlR9zdJOcw3Pv7Eo/CPYiCm+LgRCgW85E\n5Q3xLwfZtfWVJKbt91tvdcZgGkPjoI9Q7pzssfJtpF/hsGwR58KwGFcW0AlF\nmtbT4a5cD4nrfp/0VMwt20E0cJpJMDOdaJBWORFJq3/dHMoCMsRfOT6FPED/\ngH2yGBKXWBbQCmzBDJUqeG+hjI1E3K9+TGx1QwniUxs9XU+2Lo/ChMHIsrzQ\nT/0wMNSE25u643r/MM7AU8XoRLnOySe3BR/YsjJcoWaE/Dh0++KajAjnn+kA\nchgl3YquX6ryObXm+1/rAPMpGXUAKKQ1jABlX8Crp53MJoyYCZi0BSpCDj6+\nD3Fqho0ncTxScEHgWt6fpeTF9kUHnwhrDmdbXkCIdAHQfKm5mORZSKBF8y9h\nXk2ljpDxL1V58UaPzhL+yGIF97uw+tkgLXYYlVexFWQf75zwFteBnFDiHNfY\n1sZiQ4atcJW4jrgH096/Jxi3DrPmDz0zw0P9xes0iNaYocl3m/QEu9SJtMPl\niSwEONwq//eJyaN2XtMjWRFPs4YwgX0HQxXzuOjdKWGDw99vmPdwKkO74XT8\nTZ4SwFJy9iGrs5ZLO06hAFxBJJaJMyrZPwMmbo2DU5q8GWDrd48JeuBE6jOC\nyMwz\r\n=Gm6F\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCyvfL5gArRnLjMzu8UElFfm47/WXtcBlbWL3n90uxORAIhANgckiBFvdrp0oNcFXedawrMtJx3Zx1VYC7ppNdL57hX"}],"size":8322,"noattachment":false,"key":"/@n1ru4l/in-memory-live-query-store/-/@n1ru4l/in-memory-live-query-store-0.9.0-alpha-3ba5599.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-3ba5599.0_1640525430948_0.689914266447698"},"_hasShrinkwrap":false,"publish_time":1640525431200,"_cnpm_publish_time":1640525431200,"dist-tags":{"alpha":"0.11.0-alpha-20260720125639-14552d533a10d99fe5ade90b08c0facfad626bfe","latest":"0.11.0","rc":"0.11.0-rc-20260720130219-41f090c3809f65d64117b705343943e437843cda"}}