{"bugs":{"url":"https://github.com/apollographql/apollo-link/issues"},"dist":{"shasum":"288cbec15ff33e07cc423488d05118554d5688a4","tarball":"https://registry.npmjs.org/apollo-link-context/-/apollo-link-context-2.0.0-beta.0.tgz","fileCount":14,"integrity":"sha512-K4ZAh8QQZjkgomGumvKtROvvzvP0cOEZe6+1/Y1Z6/ugeLyZZFZpwgRQAp7o1F/Zg35G1F0A6PfxglYXXnGMGg==","signatures":[{"sig":"MEQCIHTPSoMEyvYhjYwi3wiCKYMZfgMhq1wcjNDl0dBfpKw+AiBZ9kJ7MRd59zP8tKofJP9WJFc5gWRItoO5ReKJgNUTYQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17792,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdzwWCCRA9TVsSAnZWagAAqNgP/2wRC0fg1Iw8vLlcy+E9\n6I95M3KoFW0jS8ElM5dC23hJ7nVXD7eXWxHv+32gQHjCIrk/uQwq99b063Re\n5AXzj2VodeSkwp7x9lFtWeAxcTwv+2fuY7ivRs62GMq54i5M5bGvvD+2hCpI\nCov7IZB0kwVJrCZi6ZHBBhwTnP6pkZqRFfihvh/nlHbb4cN6iL47BmmTytfQ\nhjTbnVU7Fz8cn01Wcefb6Ax+TLJsZrnHw4gPWY+aIvBwtXgDvxdQcCmBnVJZ\nubbQKLyngHs1Pv7D4Px8oCP2TPPn3mU7UoWUHVQr1aUAIWxIycR0WUvTYBeH\nkIdATmlLT2cRifTSfo60/HbeN6kYQkG5gQuuLYkvWGO8E6ccSmylGOiBo++X\nolR0SM1l0F7XMwyvChIq1v4IJfTNrfda3R43LOtIHuQy9ucVg3ClIG3m5Stf\nkwyAu2ZMdLHnFzEgMl9hLU9s4zTErWv8EZtrdFeehUyRrS7LuvacNGMNtQ6k\nFZBXQa8+IUnM4OrV8li9aS+aU5FsOHwiV9G0geBeR3VwsCKbwBahFT7+aJFg\ntUJx6MvRjGowPeKlrTkXmZebA8oI1HAd2nenlaiCJv7PNpFhzV5lcm61p6x4\nyvtE9xXIIauMgegBgjzbdX4cho2Sv1HYE2KGDWQHHR1H3oI3k8/HcPlM/lvO\nYYMu\r\n=x5+t\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"testURL":"http://localhost","testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","transform":{".(ts|tsx)":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","json"]},"main":"./lib/index.js","name":"apollo-link-context","author":{"name":"James Baxley","email":"james@meteor.com"},"module":"./lib/bundle.esm.js","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","gitHead":"150213d6b1ee2ecf5a6c8f7f46acf53b639edb0d","license":"MIT","scripts":{"lint":"tslint -c \"../../tslint.json\" -p tsconfig.json -c ../../tslint.json src/*.ts","test":"npm run lint && jest","build":"tsc && rollup -c","clean":"rimraf lib/* && rimraf coverage/*","watch":"tsc -w -p . & rollup -c -w","prepare":"npm run build","coverage":"jest --coverage","filesize":"../../scripts/minify","prebuild":"npm run clean"},"typings":"./lib/index.d.ts","_npmUser":{"name":"apollo-bot","email":"npm@apollographql.com"},"homepage":"https://github.com/apollographql/apollo-link#readme","repository":{"url":"git+https://github.com/apollographql/apollo-link.git","type":"git"},"_npmVersion":"lerna/3.18.4/node@v10.15.3+x64 (darwin)","description":"An easy way to set and cache context changes for Apollo Link","directories":{},"maintainers":[{"name":"apollo-bot","email":"npm@apollographql.com"},{"name":"evanshauser","email":"evanshauser@gmail.com"},{"name":"jbaxleyiii","email":"james@meteor.com"},{"name":"peggyrayzis","email":"peggyrayzis@gmail.com"}],"sideEffects":false,"_nodeVersion":"10.15.3","dependencies":{"tslib":"^1.9.3","@apollo/client":"^3.0.0-beta.10"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"24.9.0","rimraf":"2.7.1","rollup":"1.27.0","tslint":"5.20.1","graphql":"14.5.8","ts-jest":"22.4.6","typescript":"3.0.3","@types/jest":"24.0.23","graphql-tag":"2.10.1","@types/graphql":"14.2.3"},"_npmOperationalInternal":{"tmp":"tmp/apollo-link-context_2.0.0-beta.0_1573848450387_0.5653184103504243","host":"s3://npm-registry-packages"},"_id":"apollo-link-context@2.0.0-beta.0","version":"2.0.0-beta.0"}