{"name":"@n1ru4l/in-memory-live-query-store","version":"0.8.0-alpha-35682dd.0","peerDependencies":{"graphql":"^15.4.0 || ^16.0.0"},"dependencies":{"@graphql-tools/utils":"^8.5.2","@n1ru4l/graphql-live-query":"0.9.0-alpha-35682dd.0","@n1ru4l/push-pull-async-iterable-iterator":"^3.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.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 } 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\ninMemoryLiveQueryStore\n  .execute({\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  })\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 `InMemoryLiveQueryStore.execute` function is a drop-in replacement for the default `execute` function exported from `graphql-js`.\n\nPass it to your favorite graphql transport that supports returning `AsyncIterator` 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\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 { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'\nimport {\n  execute as defaultExecute,\n  ExecutionArgs,\n  ExecutionResult\n} from 'graphql'\nimport { LiveExecutionResult } from '@n1ru4l/graphql-live-query'\n\ndeclare type MaybePromise<T> = T | Promise<T>\n\ndeclare type ExecutionParameter =\n  | Parameters<typeof defaultExecute>\n  | [ExecutionArgs]\n\nexport interface LiveQueryStore {\n  invalidate: (identifiers: Array<string> | string) => Promise<void>\n  execute: (\n    ...args: ExecutionParameter\n  ) => MaybePromise<\n    | AsyncIterableIterator<ExecutionResult | LiveExecutionResult>\n    | ExecutionResult\n  >\n}\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) {\n    this.pub = new Redis(redisUrl)\n    this.sub = new Redis(redisUrl)\n    this.liveQueryStore = new InMemoryLiveQueryStore()\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  execute(...args: ExecutionParameter) {\n    return this.liveQueryStore.execute(...args)\n  }\n}\n```\n","readmeFilename":"README.md","gitHead":"35682ddd702e25e86bfa88e00a32a662433fc564","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.8.0-alpha-35682dd.0","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-GMduBMsfKfXn/RLQfrsUVHDPIRAVpWDSfRN/SpD0ypj7tSusvs/GxKsC0SS+ptiKojxdW41LRMKgEl/HcweR8Q==","shasum":"abcf2fde4a7c0875e9fee77adf6e5cab0ecbc791","tarball":"http://registry-npm.ywwl.com/@n1ru4l/in-memory-live-query-store/download/@n1ru4l/in-memory-live-query-store-0.8.0-alpha-35682dd.0.tgz","fileCount":19,"unpackedSize":50640,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDSqi4nAQlV+u6OxGsr1u6bGbuZPKmzFRUv6PkSPkL7gQIhAICzsLH0WP7hq6HR4f5CeWQJwSEuTD2EYlVgvEw1Ec82"}],"size":8865,"noattachment":false,"key":"/@n1ru4l/in-memory-live-query-store/-/@n1ru4l/in-memory-live-query-store-0.8.0-alpha-35682dd.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.8.0-alpha-35682dd.0_1635961082701_0.48890438814639525"},"_hasShrinkwrap":false,"publish_time":1635961082841,"_cnpm_publish_time":1635961082841,"dist-tags":{"alpha":"0.11.0-alpha-20260720125639-14552d533a10d99fe5ade90b08c0facfad626bfe","latest":"0.11.0","rc":"0.11.0-rc-20260720130219-41f090c3809f65d64117b705343943e437843cda"}}