Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 2 Examples of "apollo-server-cache-redis in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'apollo-server-cache-redis' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

}
}`,
      },
    ],
  },
  introspection: process.env.NODE_ENV !== 'production',
  maxFileSize: 25 * 1024 * 1024, // 25MB
  engine: false,
  tracing: false,
  validationRules: [depthLimit(10)],
  cacheControl: {
    calculateHttpHeaders: false,
    // Cache everything for at least a minute since we only cache public responses
    defaultMaxAge: 60,
  },
  cache: new RedisCache({
    ...config,
    prefix: 'apollo-cache:',
  }),
  plugins: [
    responseCachePlugin({
      sessionId: ({ context }) => (context.user ? context.user.id : null),
      // Only cache public responses
      shouldReadFromCache: ({ context }) => !context.user,
      shouldWriteToCache: ({ context }) => !context.user,
    }),
  ],
});

export default server;
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import _ from 'lodash'
import responseCachePlugin from 'apollo-server-plugin-response-cache'
import { RedisCache } from 'apollo-server-cache-redis'
import { formatError, Exception, responseLogger, queryLogger, session, redis } from './lib'
import { typeDefs, resolvers } from './src'
import directives from './src/directives'
import * as utils from './src/utils'
import sequelize, { models, contextOption } from './db'
import config from './config'
import { AppContext, KoaContext } from './type'
import { auth, context } from './middlewares'
import httpStatusPlugin from './src/plugin/httpStatus'

const cache = new RedisCache({
  host: config.redis.host,
  password: config.redis.password
})

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context ({ ctx }: { ctx: KoaContext }): AppContext {
    const body = ctx.request.body || {}
    queryLogger.info(body.query, {
      operationName: body.operationName,
      query: body.query,
      variables: body.variables,
      ip: ctx.request.ip,
      user: ctx.user
    })

Is your System Free of Underlying Vulnerabilities?
Find Out Now