{"name":"@envelop/live-query","version":"2.0.0","sideEffects":false,"peerDependencies":{"@envelop/core":"^1.7.0","graphql":"^14.0.0 || ^15.0.0 || ^16.0.0"},"dependencies":{"@graphql-tools/utils":"^8.0.1","@n1ru4l/graphql-live-query":"^0.9.0","@n1ru4l/in-memory-live-query-store":"^0.9.0"},"repository":{"type":"git","url":"git+https://github.com/dotansimha/envelop.git","directory":"packages/plugins/live-query"},"author":{"name":"Dotan Simha","email":"dotansimha@gmail.com"},"license":"MIT","main":"index.js","module":"index.mjs","typings":"index.d.ts","typescript":{"definition":"index.d.ts"},"exports":{".":{"require":"./index.js","import":"./index.mjs"},"./*":{"require":"./*.js","import":"./*.mjs"},"./package.json":"./package.json"},"gitHead":"815dfeb9d326c64f4e4c346f4dc73e3cd299dafb","description":"The easiest way of adding live queries to your GraphQL server!","bugs":{"url":"https://github.com/dotansimha/envelop/issues"},"homepage":"https://github.com/dotansimha/envelop#readme","_id":"@envelop/live-query@2.0.0","_nodeVersion":"17.3.0","_npmVersion":"8.3.0","dist":{"integrity":"sha512-W9wQgIX3Od5fQPKwDU59qWbSPYfyPlzdscfZtJGPbioKFTW/toBefnGZdyCru6Grl1k2L2LCUa2AFuuPY7YDZQ==","shasum":"3f12bbbf815d3c2a38dc0a9b1d329011c140e95d","tarball":"http://registry-npm.ywwl.com/@envelop/live-query/download/@envelop/live-query-2.0.0.tgz","fileCount":5,"unpackedSize":10171,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2FCuCRA9TVsSAnZWagAAbNEP/1g/wGo04nPdcU50QmO3\nC0E20sE5yJ9YpfrJQgvSHjJoGn0RHih10A1RuP7LrHuTZrjvTi0JObcDhKbk\nGumlKeqbKmAvMNYEc1tsOrzr/HoybuFufe54Ir3alCT8K3nrzgXTK31oMFtv\nvmZvbJUOaTIn6lq05Eg7km5Y8zAA52jvD4+H107HvcvHyWVLOr8ubVQR9Dmt\ngVakiP00sikWjN21JCAtcqyrsMJxGHEdaRWsesVQx/TBjq58v0UjetpW1DQI\nziZTbATSIVkHjsSb9fdxMAiC/fxcDZGyss2kdAOvNDDWXkAq2e3dQ+V4CjJe\nX7V17ZnZ0ZlfTtNmBdUE/Pe2eAPosRxpQ4/BbDefFWndPoG6hYeAvAgNqrIc\nwJzFiBalkk20tr4Iy5+oEZ8UgWRmPnP0rEzVtOJGUApFWhnlJL5/KebRd9hV\n/RNRk9GdDJdRhJFVrzBhuHmxWsLZjbtX/gNwgJ5hd4jOIYu8CxWJ365e+RhL\n374M6TeOtgx0lDeuc1yrtsh60+ZG+7FybV3UHy9AgPXtd8r3YF7OKv95Kj60\nucUStYPxBU9+2T95cIyxgrOV5srKN85LH6sg0DVb9QonRB5kLZCIoslAYCfN\nA7MvWh2sMMlkzdE42foSykWcrK8DXh6aMWMPb317KWBfP0gBYFewzzg1TTvj\n9DSU\r\n=szk0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEF5RasCoeacCIH0ZlxajbaHUS3X/Ww1JvnoM9eDpcHyAiEA+4RmK/ZPq3azYLSAjm09flq+99RGoRXTQA2SzL4i9eI="}],"size":2722,"noattachment":false,"key":"/@envelop/live-query/-/@envelop/live-query-2.0.0.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_2.0.0_1641566382350_0.457267189721708"},"_hasShrinkwrap":false,"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\nstale 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\noperation 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 { execute, parse, specifiedRules, subscribe, validate } from 'graphql'\nimport { envelop, useEngine, useExtendContext, useSchema } from '@envelop/core'\nimport { useLiveQuery } from '@envelop/live-query'\nimport { makeExecutableSchema } from '@graphql-tools/schema'\nimport { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'\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  plugins: [\n    useEngine({ parse, validate, specifiedRules, execute, subscribe }),\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\npayload that is sent over the wire from the server to the client. We recommend using the\n`@n1ru4l/graphql-live-query-patch-jsondiffpatch` patch generator.\n[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 { applyLiveQueryJSONDiffPatchGenerator } from '@n1ru4l/graphql-live-query-patch-jsondiffpatch'\nimport { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'\n\nconst liveQueryStore = new InMemoryLiveQueryStore()\n\nconst plugin = useLiveQuery({\n  liveQueryStore,\n  applyLiveQueryPatchGenerator: applyLiveQueryJSONDiffPatchGenerator\n})\n```\n\n## Further information\n\nThis plugin requires you to use a graphql transports that supports usage of the `@defer` and\n`@stream` directives, as it is built upon the same concepts (return an `AsyncIterable` from\n`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)\nor the\n[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","publish_time":1641566382536,"_cnpm_publish_time":1641566382536,"dist-tags":{"alpha":"7.0.0-alpha-20231016001432-c05b6f10","latest":"7.0.0","rc":"7.0.0-rc-20231016080110-7628eb2d"}}