{"name":"apollo-link-context","version":"1.0.12","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/bundle.umd.js","module":"./lib/index.js","jsnext:main":"./lib/index.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 .","bundle":"rollup -c","clean":"rimraf lib/* && rimraf coverage/*","coverage":"jest --coverage","filesize":"npm run build && npm run build:browser","lint":"tslint --type-check -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","prepublishOnly":"npm run clean && npm run build","test":"jest","watch":"tsc -w -p . & rollup -c -w"},"dependencies":{"apollo-link":"^1.2.6"},"devDependencies":{"@types/graphql":"14.0.3","@types/jest":"22.2.3","browserify":"16.2.3","graphql":"14.0.2","graphql-tag":"2.10.0","jest":"22.4.4","rimraf":"2.6.1","rollup":"0.67.4","ts-jest":"22.4.6","tslint":"5.11.0","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"],"mapCoverage":true,"testURL":"http://localhost"},"_id":"apollo-link-context@1.0.12","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"dist":{"integrity":"sha512-gb4UptV9O6Kp3i5b2TlDEfPSL2LG//mTSb3zyuR5U2cAzu/huw98f1CCxcjUKTrlIMsQuE6G/hbaThDxnoIThQ==","shasum":"02d72e621a3b75239d4419a9bfd38d8bd9bb0d3f","tarball":"http://registry-npm.ywwl.com/apollo-link-context/download/apollo-link-context-1.0.12.tgz","fileCount":8,"unpackedSize":11314,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcFF7tCRA9TVsSAnZWagAAz20P+weThT1zurFGpIalRmWi\ndbWpdujvgLdVpDnlwzj0jKaRpzaLjA1OIceTMe0WP0mrBtwftzbaCwAlYFo+\nFswwpVnn7lupgkT5zPqix0pnG9h+zLWSuZrFwFGHbV4mnRfMkgLNVgGjjXhd\npXpWQM3085GR7A7jxHcd3tGE4UYZkueJ6CPGfUknwuSxRDQp0hS0HxKfB2Qt\nziSaB6Y0AJKSu9amePiAekoyM6cz9/reD00ZhYk/GCsYTuQnJZmH9Hli+DGY\nEb6h5inepPkVAUW4s6NToSylpKmqgC+SNApI6bxNOBWajkghx1p7N5Gk0G04\nmvjFExXwznyqUkhNRFFIIFDjbnDjqu3ijfBU791qxQx99Ro8fiaN0VzIQ/9A\nj0MRy3S3XgjWgXtBMG/n26eBA7DVTg/vA5t+yGvPlmj2O3hLWjenUWUsjqeo\n9rPn+hflJLEUVXeoQCn/wi6y93KFE6XFbBct+WtPPy95WNzqleOsKl4nxuM5\nQAUWLrlVW5W4vspc4zh64N2fZDwPMEH1gKa0CONcbnOvpC99z8DLq7ITfrwT\nTh/6IACCk5qVnOJlRc0l2tpLPUm3ByaHZjdSerJVp14aNhu+dmkKXIzYQlCE\nqzQ4OhrynPkPirLoeh7q6PVK8bhyWCD1uys3ZqlLjSlvRHe+qpdDVKa9ZmKi\njBBW\r\n=kKJu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCUrRPVowbTqrT3V/+2d/cY93HSOR0hhJYjp5zjRuzhcgIgIDL4veSDWVeRynUq+t0fzROLfx20cVI88npPqS5aP14="}],"size":3898,"noattachment":false,"key":"/apollo-link-context/-/apollo-link-context-1.0.12.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.12_1544838892888_0.5502940984976858"},"_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":1544838893286,"_cnpm_publish_time":1544838893286,"dist-tags":{"beta":"2.0.0-beta.0","latest":"1.0.20"}}