apollographql / apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
https://www.apollographql.com/docs/apollo-server/
MIT License
13.77k stars 2.03k forks source link

bug in apollo-server-plugin-response-cache #5965

Closed kodeine closed 2 years ago

kodeine commented 2 years ago

Getting an error, any idea's?

{"stacktrace":["TypeError: Cannot read properties of null (reading 'cachePolicy')","    at cacheGet (/Projects/service-gateway/node_modules/apollo-server-plugin-response-cache/src/ApolloServerPluginResponseCache.ts:177:61
glasser commented 2 years ago

What version of this package and other Apollo Server packages are you using?

kodeine commented 2 years ago

@glasser Thank you for taking interest in this, following is the package.json

"dependencies": {
    "@apollo/gateway": "^0.42.0",
    "@nestjs/common": "8.2.1",
    "@nestjs/config": "1.1.0",
    "@nestjs/core": "8.2.1",
    "@nestjs/graphql": "9.1.1",
    "@nestjs/microservices": "8.2.1",
    "@nestjs/platform-express": "8.2.1",
    "apollo-server-cache-redis": "3.3.0",
    "apollo-server-plugin-response-cache": "3.4.0",
    "class-transformer": "0.4.0",
    "class-validator": "0.13.1",
    "graphql": "15.7.2",
    "helmet": "4.6.0",
    "http-proxy-middleware": "2.0.0",
    "ioredis": "^4.28.2",
    "joi": "17.4.0",
    "jsonwebtoken": "8.5.1",
    "reflect-metadata": "0.1.13",
    "rimraf": "3.0.2",
    "rxjs": "7.2.0",
    "uuid": "^8.3.2"
  },
export const redisCache: Redis = new Redis({
  host: process.env.REDIS_HOST,
  port: process.env.REDIS_PORT,
  password: process.env.REDIS_PASSWORD,
  options: {
    connectionName: process.env.APP_NAME,
  },
});

......
        gateway: {
          serviceList: config.get('SERVICES_LIST'),
        },
        server: {
          playground: config.get('NODE_ENV') === 'development',
          cache: redisCache,
          persistedQueries: {
            cache: new BaseRedisCache({
              client: redisCache,
            }),
          },
          plugins: [
            ApolloServerPluginCacheControl({ defaultMaxAge: 300 }),
            responseCachePlugin({ cache: redisCache }),
          ],
glasser commented 2 years ago

Can you share your full package-lock.json? Nest makes it hard to tell what versions you are using.

On Thu, Dec 23, 2021, 4:18 PM Kodeine @.***> wrote:

@glasser https://github.com/glasser Thank you for taking interest in this, following is the package.json

"dependencies": { @./gateway": "^0.42.0", @./common": "8.2.1", @./config": "1.1.0", @./core": "8.2.1", @./graphql": "9.1.1", @./microservices": "8.2.1", @.***/platform-express": "8.2.1", "apollo-server-cache-redis": "3.3.0", "apollo-server-plugin-response-cache": "3.4.0", "class-transformer": "0.4.0", "class-validator": "0.13.1", "graphql": "15.7.2", "helmet": "4.6.0", "http-proxy-middleware": "2.0.0", "ioredis": "^4.28.2", "joi": "17.4.0", "jsonwebtoken": "8.5.1", "reflect-metadata": "0.1.13", "rimraf": "3.0.2", "rxjs": "7.2.0", "uuid": "^8.3.2" },

export const redisCache: Redis = new Redis({ host: process.env.REDIS_HOST, port: process.env.REDIS_PORT, password: process.env.REDIS_PASSWORD, options: { connectionName: process.env.APP_NAME, }, });

...... gateway: { serviceList: config.get('SERVICES_LIST'), }, server: { playground: config.get('NODE_ENV') === 'development', cache: redisCache, persistedQueries: { cache: new BaseRedisCache({ client: redisCache, }), }, plugins: [ ApolloServerPluginCacheControl({ defaultMaxAge: 300 }), responseCachePlugin({ cache: redisCache }), ],

— Reply to this email directly, view it on GitHub https://github.com/apollographql/apollo-server/issues/5965#issuecomment-1000575955, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAECVHYEVYKXQTNXOGL6J3USO363ANCNFSM5KTLPIFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

kodeine commented 2 years ago

@glasser attached is the package-lock file.

package-lock.json.zip

glasser commented 2 years ago

One thing I'm seeing is that you have a copy of apollo-server-core v2 installed below @ntegral/nestjs-sentry (you end up with two copies of @nestjs/graphql, one v8 and one v9. It looks like @ntegral/nestjs-sentry@3.0.7 (released this week) relaxes its dependency to allow v9 of @nestjs/graphql, so upgrading to that should hopefully clear up the "two copies of Apollo Server" problem.

If you're still having issue once there's no apollo-server-core v2 in your package-lock.json, please turn this into a minimal reproduction by shrinking your project to the smallest size possible that still shows the issue and providing us with clear reproduction steps that require no creativity to apply (typically starting with git clone or looking at a codesandbox.io sandbox). I'll be happy to reopen the issue if there's an easy reproduction. Also is this something that completely breaks your cache and it never works, or just once in a while?

BTW, it looks like what is happening is that the literal string null is getting stored in your cache somehow, which seems pretty surprising.