{"name":"@envelop/live-query","version":"5.0.0-alpha-20220915162551-80e79e83","sideEffects":false,"peerDependencies":{"@envelop/core":"3.0.0-alpha-20220915162551-80e79e83","graphql":"^14.0.0 || ^15.0.0 || ^16.0.0"},"dependencies":{"@graphql-tools/utils":"^8.8.0","@n1ru4l/graphql-live-query":"^0.10.0","@n1ru4l/in-memory-live-query-store":"^0.10.0","@n1ru4l/graphql-live-query-patch":"^0.7.0","tslib":"^2.4.0"},"repository":{"type":"git","url":"git+https://github.com/n1ru4l/envelop.git","directory":"packages/plugins/live-query"},"author":{"name":"Dotan Simha","email":"dotansimha@gmail.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.cts","default":"./cjs/index.js"},"import":{"types":"./typings/index.d.ts","default":"./esm/index.js"},"default":{"types":"./typings/index.d.ts","default":"./esm/index.js"}},"./*":{"require":{"types":"./typings/*.d.cts","default":"./cjs/*.js"},"import":{"types":"./typings/*.d.ts","default":"./esm/*.js"},"default":{"types":"./typings/*.d.ts","default":"./esm/*.js"}},"./package.json":"./package.json"},"readme":"## `@envelop/live-query`\n\nThe easiest way of adding live queries to your GraphQL server!\n\nPush new data to your clients automatically once the data selected by a GraphQL operation becomes stale by annotating your query operation with the `@live` directive.\n\n```graphql\nquery UserProfile @live {\n  me {\n    id\n    login\n    bio\n  }\n}\n```\n\nThe invalidation mechanism is based on GraphQL ID fields and schema coordinates. Once a query operation has been invalidated, the query is re-executed and the result is pushed to the client.\n\n## Installation\n\n```bash\nyarn add @envelop/live-query @n1ru4l/in-memory-live-query-store\n```\n\n## Usage Example\n\n### `makeExecutableSchema` from `graphql-tools`\n\n```ts\nimport { parse, validate, execute, subscribe } from 'graphql'\nimport { envelop, useSchema, useExtendContext } from '@envelop/core'\nimport { useLiveQuery } from '@envelop/live-query'\nimport { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'\nimport { makeExecutableSchema } from '@graphql-tools/schema'\n\nconst schema = makeExecutableSchema({\n  typeDefs: [\n    /* GraphQL */ `\n      type Query {\n        greetings: [String!]\n      }\n    `,\n    GraphQLLiveDirectiveSDL\n  ],\n  resolvers: {\n    Query: {\n      greetings: (_, __, context) => context.greetings\n    }\n  }\n})\n\nconst liveQueryStore = new InMemoryLiveQueryStore()\n\nconst greetings = ['Hello', 'Hi', 'Ay', 'Sup']\n// Shuffle greetings and invalidate queries selecting Query.greetings every second.\nsetInterval(() => {\n  const firstElement = greetings.pop()\n  greetings.unshift(firstElement)\n  liveQueryStore.invalidate('Query.greetings')\n}, 1000)\n\nconst getEnveloped = envelop({\n  parse,\n  validate,\n  execute,\n  subscribe,\n  plugins: [\n    useSchema(schema),\n    useLiveQuery({ liveQueryStore }),\n    useExtendContext(() => ({ greetings }))\n    /* other plugins */\n  ]\n})\n```\n\n### `GraphQLSchema` from `graphql`\n\nYou need to pass the `GraphQLLiveDirective` to the list of directives:\n\n```tsx\nimport { GraphQLSchema } from 'graphql'\nimport { GraphQLLiveDirective } from '@envelop/live-query'\n\nconst schema = new GraphQLSchema({\n  directives: [...specifiedDirectives, GraphQLLiveDirective]\n})\n```\n\n### Applying a patch middleware\n\nBy using a patch middleware you can significantly reduce the size of the GraphQL execution result payload that is sent over the wire from the server to the client.\nWe recommend using the `@n1ru4l/graphql-live-query-patch-jsondiffpatch` patch generator. [You can learn more about it here](https://github.com/n1ru4l/graphql-live-query/tree/main/packages/graphql-live-query-patch-jsondiffpatch).\n\n```bash\nyarn add @n1ru4l/graphql-live-query-patch-jsondiffpatch\n```\n\n```ts\nimport { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'\nimport { applyLiveQueryJSONDiffPatchGenerator } from '@n1ru4l/graphql-live-query-patch-jsondiffpatch'\n\nconst liveQueryStore = new InMemoryLiveQueryStore()\n\nconst plugin = useLiveQuery({ liveQueryStore, applyLiveQueryPatchGenerator: applyLiveQueryJSONDiffPatchGenerator })\n```\n\n## Further information\n\nThis plugin requires you to use a graphql transports that supports usage of the `@defer` and `@stream` directives, as it is built upon the same concepts (return an `AsyncIterable` from `execute`).\n\nThe following transports have been successfully tested:\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) | GraphQL over Socket.io (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)                                                                | [GraphQL over HTTP](https://github.com/graphql/graphql-over-http) (IncrementalDelivery/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)                                                                          | [GraphQL over WebSocket](https://github.com/graphql/graphql-over-http/pull/140) (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| [`graphql-sse`](https://github.com/enisdenjo/graphql-sse)                                                                        | [GraphQL over Server-Sent Events](https://github.com/enisdenjo/graphql-sse/blob/master/PROTOCOL.md) (SSE) | [![npm version](https://badge.fury.io/js/graphql-sse.svg)](https://github.com/enisdenjo/graphql-sse)                                                                            | [![npm downloads](https://img.shields.io/npm/dm/graphql-sse.svg)](https://github.com/enisdenjo/graphql-sse)                                                                        |\n\nFor more details check out the [live query repository](https://github.com/n1ru4l/graphql-live-query) or the [introduction blog post](https://the-guild.dev/blog/subscriptions-and-live-queries-real-time-with-graphql).\n\n[There is also a full schema example available.](https://github.com/n1ru4l/graphql-live-query/blob/main/packages/todo-example/server-ws/src/schema.ts)\n","readmeFilename":"README.md","gitHead":"80e79e83ebf6491979501fb2e44cf8e5da4a6ec6","description":"The easiest way of adding live queries to your GraphQL server!","bugs":{"url":"https://github.com/n1ru4l/envelop/issues"},"homepage":"https://github.com/n1ru4l/envelop#readme","_id":"@envelop/live-query@5.0.0-alpha-20220915162551-80e79e83","_nodeVersion":"18.9.0","_npmVersion":"8.19.1","dist":{"integrity":"sha512-1XRNCuzz94R2XRJzQQc3xPP8qITuW4ig+g3IudWIf5Tpz0IV9ujRHhHxMpCF6vMfSnlJuR5N/lODu767Gt0aNQ==","shasum":"edf743d40149d1243b5e014b1b2696df7bc8b3e4","tarball":"http://registry-npm.ywwl.com/@envelop/live-query/download/@envelop/live-query-5.0.0-alpha-20220915162551-80e79e83.tgz","fileCount":7,"unpackedSize":13638,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDoNrri4EWmqGJyo+ZZSlWKPFa22F4Fp43whyaViGx0AAiEA+u5s42pofpHEgdbAKZ+x4u11PEJWFDF0v5VeEOJCQCc="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjI1I0ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpI2RAAoZbHk/ckNXksbNJSYUq43sWst6ZcVraxptClBqTLC6h64Pvv\r\nL3P7v1FlYKH5UDPXNumk2eBb7uInqX6kUZ45EqIhv8TScYU1RXn9R8eMHUAF\r\nNHZU7Y60O1fqY9sBDwEVjd1cS9sj5vzJcgKbtJVOh9An5eeEm+ecg/yWJ7OC\r\n/QCeiBJDenlefOPh2JV1Q6v1pURmNYieqY3fSpDbvM5wwsSk0hlf9D9JHdcB\r\nsKQJP1JA82BMwVqqVvM7rqltrxgV6THyJv5TtkzXxC8lF12EBOP7GwCR8m/K\r\nh3rh7TlB6jxV9BjiodMrNbS7dm42/NjZpZxD1QLjYA0rZcNT4De69UcrYPGR\r\nCvxbCn4uEhrYwPglWuW9B+wG5wkk3A3FrxqbRSTb6uK4lNU50XamEDxa61HZ\r\nVvxKS+prYZYT8o+UVX13yrSpkItKapsdTQyXxdOjTW+UwFh8kKTjNp+pkF71\r\n8iMuNMmetfpmeI9Ud/n8eyK3tLFOwKdEDdJHOQEI4asPiVrMxBj4ywWMS7kk\r\nzui5TDL2MPbuK+ZgkWjRqPQ/0QUU1notEd2NuU4a7myD+jRws0TA8Zgjb+Jr\r\nYaCh739+HIJWCiEKEfZwjsRi9n2bKDPmj87Q9+rOxfDRqEgRnloAVTxnNOtM\r\nVZ6PnkoTaRsr3aK6eq2V5Nwc82Qoi9oDoII=\r\n=ZXYx\r\n-----END PGP SIGNATURE-----\r\n","size":3279,"noattachment":false,"key":"/@envelop/live-query/-/@envelop/live-query-5.0.0-alpha-20220915162551-80e79e83.tgz"},"_npmUser":{"name":"dotansimha","email":"dotansimha@gmail.com"},"directories":{},"maintainers":[{"name":"dotansimha","email":"dotansimha@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/live-query_5.0.0-alpha-20220915162551-80e79e83_1663259188781_0.8205886612887883"},"_hasShrinkwrap":false,"publish_time":1663259188939,"_cnpm_publish_time":1663259188939,"dist-tags":{"alpha":"7.0.0-alpha-20231016001432-c05b6f10","latest":"7.0.0","rc":"7.0.0-rc-20231016080110-7628eb2d"}}