{"name":"apollo-link-context","version":"1.0.14","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.8"},"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"},"gitHead":"6f5d0cfb73e61c6f83caed9e37d37c4451a64c7b","_id":"apollo-link-context@1.0.14","_nodeVersion":"8.12.0","_npmVersion":"lerna/3.10.7/node@v8.12.0+x64 (darwin)","dist":{"integrity":"sha512-l6SIN7Fwqhgg5C5eA8xSrt8gulHBmYTE3J4z5/Q2hP/8Kok0rQ/z5q3uy42/hkdYlnaktOvpz+ZIwEFzcXwujQ==","shasum":"6265eef49bedadddbbcff4026d04cd351094cd6c","tarball":"http://registry-npm.ywwl.com/apollo-link-context/download/apollo-link-context-1.0.14.tgz","fileCount":29,"unpackedSize":44348,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcVKKcCRA9TVsSAnZWagAAo5wP/RU4TzEbFaj3PA99nSD5\nz9LX0YnLbXnrvmYMvMvL0lkEzge3Ds4CxqiTlAvfoybizrjfB3hWrfhYe0kO\n0wfqETVcHFj/t9PJWFgmxPl2CTI6ui1Vi4oLQOLLSoTz8g87h1SY3RKkMD2i\nv6oWoupyjOGJqEU7eQL90RnbijHlaXJqweZNI3fHYF3Rfm5wjSIQoFAoLO5I\nxzX/+9XzdA3nGD453Y9jaxbUFxeehQDbCcUqOm/RSqGpbsHRsRPmj0h+9RFW\nYtgN80WoQ3zlMri1M2vJDz9mQiMPm8YILJvpXFdHE/in54iGBq0BsGdVUub4\nj1HG1oZkRJSZd3ROGSazAaNedofSvnDkt2KJtbQqayRgFnVLZe9atZAOboNc\nbELHFzDTW8C2W+PZErqFii2GlsquxD7FTuDCvi5ueZT6vkxZjoIoHF1/Rekr\nfG0vlmGAnyA70kYUQmD92p+kwJiSIxNUHb2iEvAnozoyLodPV0lZ6Hi5BHEV\nn8QA1vdOPu4OsOrDKRGnRbC/ejmPevYfrVbq3fBgmQe7DmIlfC7IM53RA2at\nQJhUZymVpgFoVesh6uG97NB/nMrZfynZK4LlfZmi0CVzvvqmDr5RXs3H66WX\nG2uPS5wk+9Hif6Upus/vpr0fn5Bc7RAuiC/Lj/BqOcsnJt+D4FhTEY/2SinW\nj+7y\r\n=BpiH\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG86enVHAW+Yd9bWhP6gmvCVZW72rezYMOvREfAs0wzpAiEA1N2FcUpbHAyWQjbMNj165NnHd7Xe2/VVB1JdYAgfFBo="}],"size":9602,"noattachment":false,"key":"/apollo-link-context/-/apollo-link-context-1.0.14.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.14_1549050524056_0.9666918841867937"},"_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":1549050524158,"_cnpm_publish_time":1549050524158,"dist-tags":{"beta":"2.0.0-beta.0","latest":"1.0.20"}}