{"_id":"@cosva-lab/apollo-link-offline","_rev":"2-7a7778d0b780c0f48cba16b5717ef59e","name":"@cosva-lab/apollo-link-offline","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.1":{"name":"@cosva-lab/apollo-link-offline","version":"1.0.1","description":"Offline plug-in for Apollo","author":{"name":"Eduard Castellanos","email":"eduard@cosva.app"},"contributors":[{"name":"Miguel Carvajal","email":"omar@carvajalonline.com"},{"name":"Eduard Castellanos","email":"eduard@cosva.app"}],"license":"MIT","main":"./index.js","module":"./esm/index.js","typings":"./index.d.ts","sideEffects":false,"repository":{"type":"git","url":"git+https://github.com/cosva-lab/apollo-link-offline.git"},"bugs":{"url":"https://github.com/cosva-lab/apollo-link-offline/issues"},"homepage":"https://github.com/cosva-lab/apollo-link-offline#readme","publishConfig":{"access":"public"},"dependencies":{"apollo-cache-inmemory":"^1.6.5","apollo-client":"^2.6.8","apollo-link":"^1.2.13","graphql":"^14.6.0","graphql-tag":"^2.10.3","lodash":"^4.17.15","tslib":"^1.9.3","uuid":"^3.4.0"},"peerDependencies":{"graphql":"^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"},"jest":{"transform":{".(ts|tsx)":"ts-jest"},"testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js","json"],"testPathIgnorePatterns":["/node_modules/","sharedHttpTests.ts"],"testURL":"http://localhost"},"private":false,"jsnext:main":"./esm/index.js","_id":"@cosva-lab/apollo-link-offline@1.0.1","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"integrity":"sha512-xgzwfEEEOW2mw0NfoaMIj2uP1Gd943l02NqNbamyqDJ5qTSDB5OR8eqU7AKqujLldU0jgbKoEAw9RsEPDcmB1g==","shasum":"b88d78f13850be481676b15c9e8e725fbcb89db1","tarball":"https://registry.npmjs.org/@cosva-lab/apollo-link-offline/-/apollo-link-offline-1.0.1.tgz","fileCount":22,"unpackedSize":141150,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeTE6PCRA9TVsSAnZWagAAMq4P/izDD8EFjUqPhTZz6i/n\nC4kT5dBFuaMT9AEwoKjOhB/j0g4yi2Lt7zC76MJMWQCbCB07nj1888AzfuOw\nK5RU6MgEeEmBzPXNKiLpG7tEH9wFkBoHmoiQ7rZEBhoLICUAmS8NrzrWQsXd\n/2itiQeIl5J0FKcZVGPLAz2dEiQn0qA8h8VKAHTkQ4IQt11LtuNsWJ6vgvgi\nfmD5qdrM8QtLGcaBrR6qoWeRwVvjdzm/w0in88loyJdws+hTlk9A4PsycLiC\nU2VmYHMJXAdev/KaqInh3p6RMsnWeH7LtrPQgNCvzSvJGO2HUYv0DpupKpOj\nijf9u01OAy3AbgItBWiqdw1X+euU93FbzFapeskhBRCbNN0jUg3koO9wbnVr\nuE6AcnLSe84Ntkz2zzbgrKWNlqQZoAyvOlDtYh+C0i99/cvtR+8b6+Wq4Xlz\n1gMQ+nDG/12S5BiFyU4q1YmmU5fVxjuDKG8SBg8mftLfDdQ35DnEKjOEqRhp\noxg7HETAbvk9VPDWnxJEJCQ8J6rYLds8UaeWDfvv84Egt3qdyAH8qOflR5tM\nKFZ9otFN453+pmINIBd2MtSSC7IAEu6T3Dws0BWLZVBz53Rg9iJ6EUz0jNBY\nt2uEiT0Me4aeeJg7DMp+aXqk8TvdLxCUn9q8RXz6aBSZyB6Eh0144tHQadOd\nVr0D\r\n=jT7w\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEBekr7PPfZieki9xS1v0/ZgVFw8nJ5/vam/aPEZah+qAiEAqYHiMxCSaH+D1FNB49FTxt6CXQkCIFd/1FrfzHlsrkg="}]},"maintainers":[{"name":"nelsoncastellanos","email":"nelsongarzon0000@gmail.com"},{"name":"cosva","email":"andrescastellanos112013@gmail.com"}],"_npmUser":{"name":"cosva","email":"andrescastellanos112013@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/apollo-link-offline_1.0.1_1582059151111_0.3397823051223372"},"_hasShrinkwrap":false},"1.0.2":{"name":"@cosva-lab/apollo-link-offline","version":"1.0.2","description":"Offline plug-in for Apollo","author":{"name":"Eduard Castellanos","email":"eduard@cosva.app"},"contributors":[{"name":"Miguel Carvajal","email":"omar@carvajalonline.com"},{"name":"Eduard Castellanos","email":"eduard@cosva.app"}],"license":"MIT","main":"./index.js","module":"./esm/index.js","typings":"./index.d.ts","sideEffects":false,"repository":{"type":"git","url":"git+https://github.com/cosva-lab/apollo-link-offline.git"},"bugs":{"url":"https://github.com/cosva-lab/apollo-link-offline/issues"},"homepage":"https://github.com/cosva-lab/apollo-link-offline#readme","publishConfig":{"access":"public"},"dependencies":{"apollo-cache-inmemory":"^1.6.5","apollo-client":"^2.6.8","apollo-link":"^1.2.13","graphql":"^14.6.0","graphql-tag":"^2.10.3","lodash":"^4.17.15","tslib":"^1.9.3","uuid":"^3.4.0"},"peerDependencies":{"graphql":"^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"},"jest":{"transform":{".(ts|tsx)":"ts-jest"},"testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js","json"],"testPathIgnorePatterns":["/node_modules/","sharedHttpTests.ts"],"testURL":"http://localhost"},"private":false,"jsnext:main":"./esm/index.js","_id":"@cosva-lab/apollo-link-offline@1.0.2","_nodeVersion":"10.16.2","_npmVersion":"6.9.0","dist":{"integrity":"sha512-yEFDoYxapbZd6lTT136fAgFwzM88t7ydqYU0b6Wb9MybI/z/s2ip2Jk2clPyBVKtWcUB9qNr6Gox/NFF1q2eIw==","shasum":"7977c86377091feddf7beab6d9fd8f1f8d0dd411","tarball":"https://registry.npmjs.org/@cosva-lab/apollo-link-offline/-/apollo-link-offline-1.0.2.tgz","fileCount":22,"unpackedSize":135952,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeVeOlCRA9TVsSAnZWagAA+dcP/i7M0U1XsUTDh4otsm4X\nXbTXEHmKJr7LAWBKNJ4EpJmWipbNga1NJvPhelV3ecCwSBN6r+BjNztAG5mF\nEQK7/2XOG3eeL6k1d4p5JxkPZF3zq+6nL98dxAeRJfwanxLPzZIg43kLTwrT\nZzaHcAqJ4zTIeZiJfWg2gr+vhBJl+I/Ne+DC7KFvRha5f3lMBBOJpq7iwdmH\n4QbZQDVoXP1Oa3dQ5h+l3YWR4FjNtgq1zqlTPuHH6hTjzIfrPpUpwZwJ5gi5\nk9z0Gd+EiMvgRMkw2jEf41dBmb6XUtSFJMBYyQRGy7Ld82pbmzlLmQGEF2ky\nIy6SqG1W3RT2dJZLfG323UeZkM1UKInWhPrs5qvaRJPSLrHEq0pyItoHPjVW\n3bypQ9cYLL4fdUb+2N+1DwqvPQFdekJS89tCbP/mt5LXRA95jcv7MIeRWKlD\nbVMD+fbQpvW6n/6x1gsR7zOvxjF787OiSnqaANeeW5rNSkmbP412eAi+r70g\nGFqFngNA0w64bf8tPpxN5yUOMCtv2FfdSBZ0QilbsfqeI34BpbbDSMm82tnH\nPb4GmH8JrrVeBlZgb8WUvgvg8An8HYa0lTkO9RMoTfA6tyCRTI3RwvxlWPum\ntLHHOtgduOr1KpLDxtrhwjhnmAxzKPQtjDglQQ9bPlWFWLd9k+429RG3SGqX\nNG9o\r\n=HpMg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8rAGsiRj08LfnVo3yQXgSaorY/VBaNNxWXW8F/iuS8QIhAOPoUb1uQ8Xwz3b3FzNYhgXqT/cjEQY5Fk7VqdFxpdo5"}]},"maintainers":[{"name":"cosva","email":"andrescastellanos112013@gmail.com"},{"name":"nelsoncastellanos","email":"nelsongarzon0000@gmail.com"}],"_npmUser":{"name":"cosva","email":"andrescastellanos112013@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/apollo-link-offline_1.0.2_1582687141480_0.09371515027653432"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-18T20:52:30.905Z","1.0.1":"2020-02-18T20:52:31.246Z","modified":"2022-04-05T01:26:58.941Z","1.0.2":"2020-02-26T03:19:01.597Z"},"maintainers":[{"name":"cosva","email":"andrescastellanos112013@gmail.com"},{"name":"nelsoncastellanos","email":"nelsongarzon0000@gmail.com"}],"description":"Offline plug-in for Apollo","homepage":"https://github.com/cosva-lab/apollo-link-offline#readme","repository":{"type":"git","url":"git+https://github.com/cosva-lab/apollo-link-offline.git"},"contributors":[{"name":"Miguel Carvajal","email":"omar@carvajalonline.com"},{"name":"Eduard Castellanos","email":"eduard@cosva.app"}],"author":{"name":"Eduard Castellanos","email":"eduard@cosva.app"},"bugs":{"url":"https://github.com/cosva-lab/apollo-link-offline/issues"},"license":"MIT","readme":"# @cosva-lab/apollo-link-offline\r\n\r\nAn Apollo Link to queue mutations when offline or network errors exist.\r\n\r\nBiggest different between this module and other offline modules available is that this module assumes the worst. It assumes the request will not reach the server and queues all mutations, responds with optimistic response and removes the mutation from the queue when the server responds success.\r\n\r\nReason for this assumption is twofold:\r\n\r\nSpeed, since all mutations have optimistic response, the UI feels much snappier (like a local app)\r\nIn cases where the the network is NOT offline but really slow (think 2G in a third world country) and the request doesn't reach the server anyway, our queue retries until the server responds with success.\r\n\r\n## Usage\r\n\r\nImport and initialize this link in just two lines:\r\n\r\n```js\r\nimport { ApolloLink } from 'apollo-link';\r\nimport { createHttpLink, OfflineAction } from '@cosva-lab/apollo-link-offline';\r\nimport localforage from 'localforage';\r\n\r\n\r\nconst syncUserCreated: OfflineAction<Pick<\r\n  Mutation,\r\n  'createUser'\r\n>> = ({ cache, optimisticResponse }, newData) => {\r\n  // Read this https://www.apollographql.com/docs/react/caching/cache-interaction/#writequery-and-writefragment\r\n};\r\n\r\nconst offlineLink = new OfflineLink({\r\n  storage: localforage,\r\n  actions: { syncUserCreated },\r\n});\r\n\r\nconst link = ApolloLink.from([\r\n  offlineLink,\r\n  ...\r\n]);\r\n\r\n\r\nexport const client = new ApolloClient({\r\n  link,\r\n  cache,\r\n  ...\r\n});\r\n```\r\n\r\n### @offline annotation to mutations\r\n\r\napollo-link-offline needs to receive the onSync entry in the @offline annotation to\r\nknow what function to call when the data is synchronized\r\n\r\nExample: @offline (onSync: syncUserCreated)\r\n\r\n```js\r\nimport gql from 'graphql-tag';\r\n\r\nexport const CREATE_USER = gql`\r\n  mutation($name: String!) @offline(onSync: syncUserCreated) {\r\n    ...\r\n  }\r\n`;\r\n```\r\n","readmeFilename":"README.md"}