{"name":"@n1ru4l/in-memory-live-query-store","version":"0.11.0-alpha-4a0d9f8.0","peerDependencies":{"@graphql-tools/graphql":"0.1.0-alpha-20220809192840-c5b336bd"},"dependencies":{"@graphql-tools/utils":"8.9.2-alpha-20220809192840-c5b336bd","@n1ru4l/graphql-live-query":"0.11.0-alpha-4a0d9f8.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":"cjs/index.js","module":"esm/index.js","typings":"typings/index.d.ts","typescript":{"definition":"typings/index.d.ts"},"type":"module","exports":{".":{"require":{"types":"./typings/index.d.ts","default":"./cjs/index.js"},"import":{"types":"./typings/index.d.ts","default":"./esm/index.js"},"default":{"types":"./typings/index.d.ts","default":"./esm/index.js"}},"./package.json":"./package.json"},"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":"4a0d9f84d6a8cc76e4caf3ba2174b5a642e60bcb","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.11.0-alpha-4a0d9f8.0","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-aEb6Inp75kaA7ZsXgnPkSzvorzLR6/BZXFohDIUy+qDoewx2aD3KDFX2JezQnJnm08MXl0dF5IJm4QOaZ/XUNw==","shasum":"8d75ed66a280b66f5e245f5fec5be61493ba88fc","tarball":"http://registry-npm.ywwl.com/@n1ru4l/in-memory-live-query-store/download/@n1ru4l/in-memory-live-query-store-0.11.0-alpha-4a0d9f8.0.tgz","fileCount":27,"unpackedSize":54129,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEeQ0iS51DA85f93xUgahDleERN2IuSPp0W15om/M7m9AiBNVYNrUMT54paxIhbFXmj/TT6je2p4YGvaEIj420Mpvw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi9AIJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqauA//WYZ7y7cer4gDgoAvFHZCXS4AnuaTL30wL496r0wJgNuw432H\r\no5FmfIXZh653kM8CCUn1Lxk12G7b94Z7ftIPs6/gveavpAAOhhPmRNBOnzuO\r\na8GCprxlWj0F9XrcuGzf/HtfEojYt1Ncg4WS58OII93WJBljLVW/SysqYeuI\r\nR0LvlLpXTzFFf79nEgheb9EjwFbunUhn2T2ayEIGxDSs0bl1uajtNDwKqnSI\r\nJlX8IqHiAAk6jAlSy9mDI7LrFtCYVTCHiHscsUCWdPHtdFHj8EvUWzU5T10m\r\nAI9DuuBviQRjktp1GRCaVx/63vzAvVQAs0UewPT1SEw3dwz0FGIXjQbTfG/t\r\n+kYbZqF0IKOQvuUNuwwUSrj3yECuERzmgcKnOPCOXVway5VlwL8opb9HKG8s\r\njPu0C3eoVKSQxR0w/FzhJlH8DTLnx1s+1doZqX2SkXsMNAq+2NOveLYMAf7r\r\n/gCB3ksXQZuoUOBiCfb9vH/vzzZO0EL2wjQIIITOjxeFEBy7/uXk8+2RJxb1\r\nKEAmtNg5gNGQDoBBvFn0ZD2Nygri+dsTRdgEdYSI+mcObkvdWDFx5B1KrGYh\r\nQjtpiUzcFdcLTv6coFtHd8F9C6+4uzSnJDx/nvhZCqyjKxwyKjwLQcpYZRZe\r\nWGx9/5pCNtbbg8rwwFsAz+8v/AUktnDSbPo=\r\n=TUEG\r\n-----END PGP SIGNATURE-----\r\n","size":9522,"noattachment":false,"key":"/@n1ru4l/in-memory-live-query-store/-/@n1ru4l/in-memory-live-query-store-0.11.0-alpha-4a0d9f8.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.11.0-alpha-4a0d9f8.0_1660158473093_0.6647025890224836"},"_hasShrinkwrap":false,"publish_time":1660158473293,"_cnpm_publish_time":1660158473293,"dist-tags":{"alpha":"0.11.0-alpha-20260720125639-14552d533a10d99fe5ade90b08c0facfad626bfe","latest":"0.11.0","rc":"0.11.0-rc-20260720130219-41f090c3809f65d64117b705343943e437843cda"}}