apollo-server-cache-dynamodb
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

apollo-server-cache-dynamodb

npm version CircleCI

This package exports an implementation of KeyValueCache that allows using AWS DynamoDB as a backing store for resource caching in Data Sources.

Important Note!

aws-sdk is included as a peerDependency in order to help keep the package size small for deployment to AWS Lambda environments, where the sdk is available as part of the runtime.

Usage

const DynamoDB = require('aws-sdk/clients/dynamodb');
const { DynamoDBCache } = require('apollo-server-cache-dynamodb');
 
const client = new DynamoDB.DocumentClient();
const cacheOpts = {
  tableName: 'KeyValueCache', // default, table name
  partitionKeyName: 'CacheKey', // default, partition key, must be type S
  valueAttribute: 'CacheValue', // default, value attribute, must be type S
  ttlAttribute: 'CacheTTL', // default, ttl attribute, must be type N
  defaultTTL: 300, // default, ttl in seconds
};
 
const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new DynamoDBCache(client, cacheOpts),
  dataSources: () => ({
    moviesAPI: new MoviesAPI(),
  }),
});

Package Sidebar

Install

npm i apollo-server-cache-dynamodb

Weekly Downloads

20

Version

2.0.1

License

MIT

Unpacked Size

10.8 kB

Total Files

7

Last publish

Collaborators

  • hotgazpacho