{"name":"apollo-link-context","version":"1.0.15","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.9","tslib":"^1.9.3"},"devDependencies":{"@types/graphql":"14.0.7","@types/jest":"22.2.3","graphql":"14.1.1","graphql-tag":"2.10.1","jest":"22.4.4","rimraf":"2.6.3","rollup":"1.4.1","ts-jest":"22.4.6","tslint":"5.13.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":"2c960e057de9d664855bb18df4a4bd25c88bb6ef","_id":"apollo-link-context@1.0.15","_nodeVersion":"8.15.1","_npmVersion":"lerna/3.13.1/node@v8.15.1+x64 (darwin)","_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"dist":{"integrity":"sha512-CkUB0CaaNGCsiNxG6GImPSsXHL8f+lQZukl2TLdpDKao3EyCuPC9gSWvclUagwZ1TDnY8O+wJnNBDGymQiZTsA==","shasum":"9e5dc3eb874b3ed975f0bb0062a65aa946fd30a2","tarball":"http://registry-npm.ywwl.com/apollo-link-context/download/apollo-link-context-1.0.15.tgz","fileCount":89,"unpackedSize":38337,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcfwF9CRA9TVsSAnZWagAAtDEP/1rHZKJxTwXi7uFu0C6+\nagHZX3A+eb0AZQutpfsE3wrZKc29yjrXU1yB9QezkumaaYhBnA2OiCfqpnn/\nZPYttFbT94KJlndS/GIcpb+yV4cBiKVwwNhQtjidZid9GClO+sYam370i/iu\ngKP7rE1PUAT3SR8BwJVlsc98rbcut54SMJXcAE/mciMA08PDdLEHYB9CkhzG\nYvDG0nJevCM2f+NXJoqi+XQQKloxzNHlPP4216i/Fv2d+U2wtlmfkpL6yETh\ncuaMCIXW8iL4P+rKeNfNxec4naLxNTuZ2/K+dPyHi1wH5BvsZYSpDs8Oocl7\nNsA0rNqmjyKBjuQOAF4ium0BL7pBI8HvI0nNMHeDyk9TUyGKHd9RpXSqmD5k\nwLRhQV3Saw6X62p/64f3Oa77WKZ4ged0cyXSXaYav4yn4Is8PssMOsiMsABo\nuI4JPCpH4jc3p3uibgmIUS4TaLCWU0u+C1QK3/mgZpLph5VqFxYTGyhGQAb7\nOEzeBZMXr1cLV5c8W/OTHIR1S+sWxgRDkpJtXbiegGGXv/QQSJezJ9WNANOM\n8EOxaQg18hLlt6TwNgy0jUs1PzDhgWP55+3aknoOcWMR9KLZYPhjrxOjNhM5\nbfL4etTbtoAOiL9SRo2I4Fpo3t8CRxWDKPLq0j6f+r+Z3boUYcuq2rFkLtLE\nXVQm\r\n=u+jL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFo3b3ogIdv3+Qh144r+0FEMgw/68bGx55DWRz+ecvzkAiAphKuQlqxAJ/a7xOFP22HmBsWOwyE1N2YVNY52yPmh9w=="}],"size":7311,"noattachment":false,"key":"/apollo-link-context/-/apollo-link-context-1.0.15.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.15_1551827324452_0.26012697592761413"},"_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":1551827324650,"_cnpm_publish_time":1551827324650,"dist-tags":{"beta":"2.0.0-beta.0","latest":"1.0.20"}}