{"name":"apollo-link-context","version":"1.0.13","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","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:browser":"browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-link && npm run minify:browser","build":"tsc -p ./tsconfig.cjs.json","bundle":"rollup -c","clean":"rimraf lib/* && rimraf coverage/*","coverage":"jest --coverage","filesize":"npm run build && npm run build:browser","lint":"tslint -c \"../../tslint.json\" -p tsconfig.json -c ../../tslint.json src/*.ts","minify:browser":"uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js","postbuild":"npm run bundle","prebuild":"npm run clean","prepare":"npm run lint && npm run build","prepublishOnly":"npm run clean && npm run build","test":"jest","watch":"tsc -w -p . & rollup -c -w"},"dependencies":{"apollo-link":"^1.2.7"},"devDependencies":{"@types/graphql":"14.0.5","@types/jest":"22.2.3","browserify":"16.2.3","graphql":"14.1.1","graphql-tag":"2.10.1","jest":"22.4.4","rimraf":"2.6.3","rollup":"0.68.2","ts-jest":"22.4.6","tslint":"5.12.1","typescript":"3.0.3","uglify-js":"3.4.9"},"jest":{"transform":{".(ts|tsx)":"ts-jest"},"testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js","json"],"testURL":"http://localhost"},"_id":"apollo-link-context@1.0.13","_npmVersion":"5.7.1","_nodeVersion":"8.9.2","_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"dist":{"integrity":"sha512-Zlk+vEaMudzWFt1aXgOl88vFolgZhbT6A3KKiuiDg5ya9gxS5NDhW3Il8LNjw9ZEBIgj1A+kKDKuiB/+GS3PAA==","shasum":"16b811daf43295c8c9f93702a36b8c69af75e2eb","tarball":"http://registry-npm.ywwl.com/apollo-link-context/download/apollo-link-context-1.0.13.tgz","fileCount":20,"unpackedSize":40159,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcVIX1CRA9TVsSAnZWagAAJREP/20kWUBea/UjP3pWyHhf\nqUEW891Jq7HT18a1MHvUz//rbq6eHYMEs0M8MqQEcsO6djlsATbHb9gpICXg\nD1R5kX7nVflH37EG9WfBjMGpEFWQG/+m2GFmmBr6q2lQhFpgWL8n+fK0no6o\nxmz3QL1fdFJSte6rV59H6AeWZ7LogWOuiIZhwZfvsyE/Aqc57KmDQERQuSQI\nZ0G7ZZLyhYl2fb667gPhQQxNpWQG4Ky0vD3imy7VSrbBh7tXLPZ6Vd4EPAJs\nGJw0Kbx9A6NDnpm6asEK8gH61jMKeg8KYghGn6OZa/Sn+JbIvMNDKd7S9ePN\ndXGCv+nkcsoJdEBte1CORK2f7Hdd8hGPlVzzpDuVWMkaDyKcvM3UsacZgMgm\nIorxkcvyNRkaFs0OmSmKguw202WcnH4iv0/1Gy7a+k7HIbumkXgltP7NURdH\nm5FPjULTZ7xbC36uPth/PdR1bKknoMpuzTbkFQEG6Xc7lDzede3cS12sHQbG\nw+gFIeRO9S+WlsOu85RQqQ0iPs7FNvmT1co2ueXD+ASTZApSxnE7Qjxt+Gj0\nCKzhB4KM1MJI3k98iegPssbu5CVfjQcG5bxBk5nr/fqAzmya8pzGy5lmyD9Y\nUNOy7kjz1ELGBO4/NG+21k9HXhG/jpTviMXapmA6fSMOfR9mmZoeeiIaDQTK\nGOkx\r\n=Pk7F\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDjc5k7gRubKgppREr1k6zrx/iPuQrJl014+mkmwfbBAwIgDMY/uaDMsfwESsJ1icG4bEOmiNmOBj2zZRsbIk9RzMM="}],"size":8753,"noattachment":false,"key":"/apollo-link-context/-/apollo-link-context-1.0.13.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"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/apollo-link-context_1.0.13_1549043188966_0.7699634669007986"},"_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":1549043189110,"_cnpm_publish_time":1549043189110,"dist-tags":{"beta":"2.0.0-beta.0","latest":"1.0.20"}}