{"bugs":{"url":"https://github.com/apollographql/apollo-cache-control-js/issues"},"dist":{"shasum":"7f821ca9f301ae3ee8e20ce4cd69f7cac05502a8","tarball":"https://registry.npmjs.org/apollo-cache-control/-/apollo-cache-control-0.0.10.tgz","fileCount":23,"integrity":"sha512-M5a41rd+tWyvTTgM6HCXFEsheRuQ8zP2gj4SAm1oszDRncb8wD+39Ra0eMpOeXdZAAXmZe53sRuji5Qp9H7WeQ==","signatures":[{"sig":"MEQCIHIC7NSdUiTHjmnBvKco3n5rI5VqNzAdhxwDCMdjQSvZAiB0d5xAHuROipuJwNoSzvkG22Afnp1BnZpbC+J/6RM1gQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":51483},"jest":{"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","transform":{"^.+\\.tsx?$":"<rootDir>/node_modules/ts-jest/preprocessor.js"},"testEnvironment":"node","moduleFileExtensions":["ts","tsx","js","jsx","json"],"testPathIgnorePatterns":["<rootDir>/node_modules/","<rootDir>/lib/","test-utils"]},"main":"./lib/index.js","name":"apollo-cache-control","types":"./lib/index.d.ts","author":{"name":"Martijn Walraven","email":"martijn@martijnwalraven.com"},"readme":"# Apollo Cache Control (for Node.js)\n\nThis package is used to collect and expose cache control data in the [Apollo Cache Control](https://github.com/apollographql/apollo-cache-control) format.\n\nIt relies on instrumenting a GraphQL schema to collect cache control hints, and exposes cache control data for an individual request under `extensions` as part of the GraphQL response.\n\nThis data can be consumed by [Apollo Engine](https://www.apollographql.com/engine/) or any other tool to inform caching and visualize the cache policies that are in effect for a particular request.\n\n## Usage\n\n### Apollo Server\n\nApollo Server includes built-in support for Apollo Cache Control from version 1.2.0 onwards.\n\nThe only code change required is to add `tracing: true` and `cacheControl: true` to the options passed to the Apollo Server middleware function for your framework of choice. For example, for Express:\n\n```javascript\napp.use('/graphql', bodyParser.json(), graphqlExpress({\n  schema,\n  context: {},\n  tracing: true,\n  cacheControl: true\n}));\n```\n\n> If you are using `express-graphql`, we recommend you switch to Apollo Server. Both `express-graphql` and Apollo Server are based on the [`graphql-js`](https://github.com/graphql/graphql-js) reference implementation, and switching should only require changing a few lines of code.\n\n### Add cache hints to your schema\n\nCache hints can be added to your schema using directives on your types and fields. When executing your query, these hints will be added to the response and interpreted by Engine to compute a cache policy for the response. Hints on fields override hints specified on the target type.\n\n```graphql\ntype Post @cacheControl(maxAge: 240) {\n  id: Int!\n  title: String\n  author: Author\n  votes: Int @cacheControl(maxAge: 30)\n  readByCurrentUser: Boolean! @cacheControl(scope: PRIVATE)\n}\n```\n\nIf you need to add cache hints dynamically, you can use a programmatic API from within your resolvers.\n\n```javascript\nconst resolvers = {\n  Query: {\n    post: (_, { id }, _, { cacheControl }) => {\n      cacheControl.setCacheHint({ maxAge: 60 });\n      return find(posts, { id });\n    }\n  }\n}\n```\n\nIf you're using TypeScript, you need the following:\n```javascript\nimport 'apollo-cache-control';\n```\n\nIf set up correctly, for this query:\n\n```graphql\nquery {\n  post(id: 1) {\n    title\n    votes\n    readByCurrentUser\n  }\n}\n```\n\nYou should receive cache control data in the `extensions` field of your response:\n\n```json\n\"cacheControl\": {\n  \"version\": 1,\n  \"hints\": [\n    {\n      \"path\": [\n        \"post\"\n      ],\n      \"maxAge\": 240\n    },\n    {\n      \"path\": [\n        \"post\",\n        \"votes\"\n      ],\n      \"maxAge\": 30\n    },\n    {\n      \"path\": [\n        \"post\",\n        \"readByCurrentUser\"\n      ],\n      \"scope\": \"PRIVATE\"\n    }\n  ]\n}\n```\n","engines":{"node":">=4.0"},"gitHead":"08c04b9191034ea72f49c4fd2e7b6e2b71ff7020","license":"MIT","scripts":{"test":"jest","clean":"rm -rf lib","watch":"tsc -w","compile":"tsc","prepare":"npm run clean && npm run compile"},"_npmUser":{"name":"mdg","email":"npm@meteor.com"},"homepage":"https://github.com/apollographql/apollo-cache-control-js#readme","deprecated":"The functionality provided by the `apollo-cache-control` package is built in to `apollo-server-core` starting with Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#cachecontrol for details.","repository":{"url":"git+https://github.com/apollographql/apollo-cache-control-js.git","type":"git"},"_npmVersion":"5.8.0","description":"A GraphQL extension for cache control","directories":{},"maintainers":[{"name":"martijnwalraven","email":"martijn@martijnwalraven.com"},{"name":"mdg","email":"npm@meteor.com"}],"_nodeVersion":"8.10.0","dependencies":{"graphql-extensions":"^0.0.x"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^22.4.3","graphql":"^0.13.2","ts-jest":"^22.4.2","typescript":"^2.7.2","@types/jest":"^22.2.2","@types/node":"^9.6.0","graphql-tools":"^2.18.0","@types/graphql":"^0.11.8","jest-matcher-utils":"^22.4.3","@types/zen-observable":"^0.5.3"},"peerDependencies":{"graphql":"0.10.x - 0.13.x"},"_npmOperationalInternal":{"tmp":"tmp/apollo-cache-control_0.0.10_1522244028588_0.18941711881351964","host":"s3://npm-registry-packages"},"_id":"apollo-cache-control@0.0.10","version":"0.0.10"}