Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Add data cache on the resolver level #12

Open
1 task
pkarw opened this issue Dec 7, 2019 · 1 comment
Open
1 task

Add data cache on the resolver level #12

pkarw opened this issue Dec 7, 2019 · 1 comment
Labels
5: Complex feature request New feature or request

Comments

@pkarw
Copy link
Contributor

pkarw commented Dec 7, 2019

What is the motivation for adding/enhancing this feature?

At the moment, the SSR caching is supposed to work with the REST catalog endpoint only

The same output cache - including tagging - should be added on resolvers level

What are the acceptance criteria

  • SSR cache added to graphQL resolvers for key entities: product, category
@pkarw pkarw added feature request New feature or request 5: Complex labels Dec 7, 2019
@ovidiul
Copy link

ovidiul commented Feb 20, 2020

Apollo Graphql Server has a caching mechanism that can be implemented with a cache server like Redis https://www.apollographql.com/docs/apollo-server/performance/caching/ , would this be a possible solution for this issue, from my tests, it could be implemented with minimal changes across all queries.

Screenshot 2020-02-20 at 15 01 00

Screenshot 2020-02-20 at 15 47 01

The config with redis would look something like this, by modifying the ApolloServer setup in the src/index.ts file:

import responseCachePlugin from 'apollo-server-plugin-response-cache';
const { RedisCache } = require('apollo-server-cache-redis');

if (config.get('server.useOutputCache')) {
    useQueryCache = {
      cache: new RedisCache(`//${config.get('redis.host')}:${config.get('redis.port')}`),
      cacheControl: {
        defaultMaxAge: config.get('server.outputCacheDefaultTtl')
      },
      plugins: [responseCachePlugin()]
    }
  }

 if (aggregatedGraphqlConfig.hasGraphqlSupport) {
    const server = new ApolloServer({
      typeDefs: mergeTypes(aggregatedGraphqlConfig.schema, { all: true }),
      resolvers: aggregatedGraphqlConfig.resolvers,
      rootValue: global,
      playground: true,
      ...useQueryCache,
      context: integrationContext => integrationContext
    });
    server.applyMiddleware({ app, path: '/graphql' });
  } else {
    console.info(
      'No GraphQL Support enabled. Please provide at least one module supporting graphQL schema.'
    );
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
5: Complex feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants