How to use the apollo-server-caching.InMemoryLRUCache function in apollo-server-caching

To help you get started, we’ve selected a few apollo-server-caching examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ERS-HCL / nxplorerjs-microservice-starter / server / common / config / graphql.ts View on Github external
process.env.GRAPHQL_MOCK !== undefined &&
    process.env.GRAPHQL_MOCK === 'true'
      ? mocks
      : false;

  const myStarwarsAPI: any = new StarwarsAPI();

  return {
    typeDefs,
    resolvers,
    dataSources: () => {
      return {
        starwarsAPI: myStarwarsAPI
      };
    },
    cache: new InMemoryLRUCache({ maxSize: 100 }),
    schemaDirectives,
    mocks: serverMocks,
   // formatError, // Error Handler
    tracing,
    playground,
    introspection: true,
    context: async ({ req, connection }) => {
      if (connection) {
        // check connection for metadata
        return {};
      } else {
        const user = getuser(req);
        return {
          // Setup the user context as well as the dataload context
          user,
          peopleLoader,
github apollographql / apollo-server / packages / apollo-server-core / src / ApolloServer.ts View on Github external
private initializeDocumentStore(): InMemoryLRUCache {
    return new InMemoryLRUCache({
      // Create ~about~ a 30MiB InMemoryLRUCache.  This is less than precise
      // since the technique to calculate the size of a DocumentNode is
      // only using JSON.stringify on the DocumentNode (and thus doesn't account
      // for unicode characters, etc.), but it should do a reasonable job at
      // providing a caching document store for most operations.
      maxSize: Math.pow(2, 20) * 30,
      sizeCalculator: approximateObjectSize,
    });
  }
github apollographql / apollo-server / packages / apollo-gateway / src / index.ts View on Github external
private initializeQueryPlanStore(): void {
    this.queryPlanStore = new InMemoryLRUCache({
      // Create ~about~ a 30MiB InMemoryLRUCache.  This is less than precise
      // since the technique to calculate the size of a DocumentNode is
      // only using JSON.stringify on the DocumentNode (and thus doesn't account
      // for unicode characters, etc.), but it should do a reasonable job at
      // providing a caching document store for most operations.
      maxSize: Math.pow(2, 20) * 30,
      sizeCalculator: approximateObjectSize,
    });
  }
github apollographql / apollo-server / packages / apollo-server-core / src / ApolloServer.ts View on Github external
defaultMaxAge: 0,
        };
      } else {
        // Default behavior is to run default header calculation and return
        // no cacheControl extensions
        requestOptions.cacheControl = {
          stripFormattedExtensions: true,
          calculateHttpHeaders: true,
          defaultMaxAge: 0,
          ...requestOptions.cacheControl,
        };
      }
    }

    if (!requestOptions.cache) {
      requestOptions.cache = new InMemoryLRUCache();
    }

    if (requestOptions.persistedQueries !== false) {
      const {
        cache: apqCache = requestOptions.cache!,
        ...apqOtherOptions
      } = requestOptions.persistedQueries || Object.create(null);

      requestOptions.persistedQueries = {
        cache: new PrefixingKeyValueCache(apqCache, APQ_CACHE_PREFIX),
        ...apqOtherOptions,
      };
    } else {
      // the user does not want to use persisted queries, so we remove the field
      delete requestOptions.persistedQueries;
    }
github apollographql / apollo-server / packages / apollo-server-core / src / ApolloServer.ts View on Github external
// if this is local dev, introspection should turned on
    // in production, we can manually turn introspection on by passing {
    // introspection: true } to the constructor of ApolloServer
    if (
      (typeof introspection === 'boolean' && !introspection) ||
      (introspection === undefined && !isDev)
    ) {
      const noIntro = [NoIntrospection];
      requestOptions.validationRules = requestOptions.validationRules
        ? requestOptions.validationRules.concat(noIntro)
        : noIntro;
    }

    if (!requestOptions.cache) {
      requestOptions.cache = new InMemoryLRUCache();
    }

    if (requestOptions.persistedQueries !== false) {
      if (!requestOptions.persistedQueries) {
        requestOptions.persistedQueries = {
          cache: requestOptions.cache!,
        };
      }
    } else {
      // the user does not want to use persisted queries, so we remove the field
      delete requestOptions.persistedQueries;
    }

    this.requestOptions = requestOptions as GraphQLOptions;
    this.context = context;
github cvburgess / SQLDataSource / SQLCache.js View on Github external
  constructor(cache = new InMemoryLRUCache(), knex) {
    this.cache = cache;
    this.loader = new DataLoader(rawQueries =>
      Promise.all(rawQueries.map(rawQuery => knex.raw(rawQuery)))
    );
  }
github GraphQLGuide / apollo-datasource-mongodb / src / datasource.js View on Github external
initialize({ context, cache } = {}) {
    this.context = context

    const methods = createCachingMethods({
      collection: this.collection,
      cache: cache || new InMemoryLRUCache()
    })

    Object.assign(this, methods)
  }
}
github caioreis123 / market2 / backend2 / node_modules / apollo-server-core / dist / ApolloServer.js View on Github external
constructor(config) {
        this.graphqlPath = '/graphql';
        if (!config)
            throw new Error('ApolloServer requires options.');
        const { context, resolvers, schema, schemaDirectives, typeDefs, introspection, mocks, extensions, engine, subscriptions, uploads, playground } = config, requestOptions = __rest(config, ["context", "resolvers", "schema", "schemaDirectives", "typeDefs", "introspection", "mocks", "extensions", "engine", "subscriptions", "uploads", "playground"]);
        const isDev = process.env.NODE_ENV !== 'production';
        if ((typeof introspection === 'boolean' && !introspection) ||
            (introspection === undefined && !isDev)) {
            const noIntro = [NoIntrospection];
            requestOptions.validationRules = requestOptions.validationRules
                ? requestOptions.validationRules.concat(noIntro)
                : noIntro;
        }
        if (!requestOptions.cache) {
            requestOptions.cache = new apollo_server_caching_1.InMemoryLRUCache();
        }
        if (requestOptions.persistedQueries !== false) {
            if (!requestOptions.persistedQueries) {
                requestOptions.persistedQueries = {
                    cache: requestOptions.cache,
                };
            }
        }
        else {
            delete requestOptions.persistedQueries;
        }
        this.requestOptions = requestOptions;
        this.context = context;
        if (uploads !== false) {
            if (this.supportsUploads()) {
                if (uploads === true || typeof uploads === 'undefined') {

apollo-server-caching

[![npm version](https://badge.fury.io/js/apollo-server-caching.svg)](https://badge.fury.io/js/apollo-server-caching) [![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apoll

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages