{"name":"apollo-link-context","version":"1.0.20","description":"An easy way to set and cache context changes for Apollo Link","author":{"name":"James Baxley","email":"james@meteor.com"},"license":"MIT","main":"./lib/index.js","module":"./lib/bundle.esm.js","typings":"./lib/index.d.ts","sideEffects":false,"repository":{"type":"git","url":"git+https://github.com/apollographql/apollo-link.git"},"bugs":{"url":"https://github.com/apollographql/apollo-link/issues"},"homepage":"https://github.com/apollographql/apollo-link#readme","scripts":{"build":"tsc && rollup -c","clean":"rimraf lib/* && rimraf coverage/*","coverage":"jest --coverage","filesize":"../../scripts/minify","lint":"tslint -c \"../../tslint.json\" -p tsconfig.json -c ../../tslint.json src/*.ts","prebuild":"npm run clean","prepare":"npm run build","test":"npm run lint && jest","watch":"tsc -w -p . & rollup -c -w"},"dependencies":{"apollo-link":"^1.2.14","tslib":"^1.9.3"},"devDependencies":{"@types/graphql":"14.2.3","@types/jest":"24.9.0","graphql":"15.0.0","graphql-tag":"2.10.1","jest":"24.9.0","rimraf":"2.7.1","rollup":"1.29.1","ts-jest":"22.4.6","tslint":"5.20.1","typescript":"3.0.3"},"jest":{"transform":{".(ts|tsx)":"ts-jest"},"testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js","json"],"testURL":"http://localhost"},"gitHead":"1012934b4fd9ab436c4fdcd5e9b1bb1e4c1b0d98","_id":"apollo-link-context@1.0.20","_nodeVersion":"10.15.3","_npmVersion":"lerna/3.20.2/node@v10.15.3+x64 (darwin)","dist":{"integrity":"sha512-MLLPYvhzNb8AglNsk2NcL9AvhO/Vc9hn2ZZuegbhRHGet3oGr0YH9s30NS9+ieoM0sGT11p7oZ6oAILM/kiRBA==","shasum":"1939ac5dc65d6dff0c855ee53521150053c24676","tarball":"http://registry-npm.ywwl.com/apollo-link-context/download/apollo-link-context-1.0.20.tgz","fileCount":14,"unpackedSize":17881,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJej3BqCRA9TVsSAnZWagAAKDEP/3pW5ISnuC56n4nNRmMc\nl8mmK91PnDbI6NQbVa26eBCLQOg9mCvbRypEUy1g4q79QIdrfXcKgp4UU+gO\na5KOWYX6gA50r2nqX1Xyxy8x8FNJYU3Bjr5bz64iY6c+pfNFRJL6REjlVnYu\nTpEyrfDfBhLvgtVdYoFFDciZWPmT4mWvfy2vbxnm2GJtIBObw55AdJq4QkoG\nCEIf37wTjX5YatF1PgFhX+7ha4xvbpBBXiYhUI0dLp3RFbwiEh8dkAuobkB7\ngOk7GKR9vHbat0Qxmz49oiZP48GIG49YbB3s+Mjr3bMPjfhnfJIXc4eXcYqX\nVAW24EejzKISTGujUADMPHeZked6NKLIvaIPt7r1g4/SrBN1iGkOG7shxW0b\nTwI3X/U4a6ba65kH5Qz0YIMybwutUNCrcbj0qhlnzwSnOb/KoPTf+o25hUc1\noEjiSK+fPZt4867sbDpT41EHkixE4s8/Q9WWlvkA7UoNMeQf69A5T4Pbv2m2\nsqyi44paRUhRpHImxdHP7NlGAYbvKCx8kfPww9iLppKVHz9bTiLe1ZxmgmKB\nPlo1mIqFnynPDwaId9FDdbC0yJbdtjuFEUNDdfLNvD0zwiAp95Xxnwv0og/8\n/+tvkCVOporB9HiWOS0rRNLPJPWCw6rwfU5zp4pAQEwLQDkwWHbXRuTG4gj6\nih63\r\n=kX/2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC03+lJxp6n4QEbv8FIsdW7nTKwf5Mhzu3vW55d2WoNUAIhANkQxWb9U9Og6tWF3j9OkGY7ZZ9kUYyRhOy+d+uDvhI8"}],"size":5124,"noattachment":false,"key":"/apollo-link-context/-/apollo-link-context-1.0.20.tgz"},"maintainers":[{"email":"npm@apollographql.com","name":"apollo-bot"},{"email":"evanshauser@gmail.com","name":"evanshauser"},{"email":"james@meteor.com","name":"jbaxleyiii"},{"email":"peggyrayzis@gmail.com","name":"peggyrayzis"}],"_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/apollo-link-context_1.0.20_1586458729772_0.854749059536642"},"_hasShrinkwrap":false,"readme":"---\ntitle: apollo-link-context\ndescription: Easily set a context on your operation, which is used by other links further down the chain.\n---\n\nThe `setContext` function takes a function that returns either an object or a promise that returns an object to set the new context of a request.\n\nIt receives two arguments: the GraphQL request being executed, and the previous context. This link makes it easy to perform async look up of things like authentication tokens and more!\n\n```js\nimport { setContext } from \"apollo-link-context\";\n\nconst setAuthorizationLink = setContext((request, previousContext) => ({\n  headers: {authorization: \"1234\"}\n}));\n\nconst asyncAuthLink = setContext(\n  request =>\n    new Promise((success, fail) => {\n      // do some async lookup here\n      setTimeout(() => {\n        success({ token: \"async found token\" });\n      }, 10);\n    })\n);\n```\n\n## Caching lookups\n\nTypically async actions can be expensive and may not need to be called for every request, especially when a lot of request are happening at once. You can setup your own caching and invalidation outside of the link to make it faster but still flexible!\n\nTake for example a user auth token being found, cached, then removed on a 401 response:\n\n```js\nimport { setContext } from \"apollo-link-context\";\nimport { onError } from \"apollo-link-error\";\n\n// cached storage for the user token\nlet token;\nconst withToken = setContext(() => {\n  // if you have a cached value, return it immediately\n  if (token) return { token };\n\n  return AsyncTokenLookup().then(userToken => {\n    token = userToken;\n    return { token };\n  });\n});\n\nconst resetToken = onError(({ networkError }) => {\n  if (networkError && networkError.name ==='ServerError' && networkError.statusCode === 401) {\n    // remove cached token on 401 from the server\n    token = null;\n  }\n});\n\nconst authFlowLink = withToken.concat(resetToken);\n```\n","publish_time":1586458729884,"_cnpm_publish_time":1586458729884,"dist-tags":{"beta":"2.0.0-beta.0","latest":"1.0.20"}}