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.8k stars 2.03k forks source link

responseCachePlugin is not a function packege apollo-server-plugin-response-cache #6022

Closed agitanggriawan closed 2 years ago

agitanggriawan commented 2 years ago

Hi, im trying to setup caching system in apollo server express version 3. Im following step in documentation https://www.apollographql.com/docs/apollo-server/performance/caching/#caching-with-responsecacheplugin-advanced but i got error like this

(node:2749) UnhandledPromiseRejectionWarning: TypeError: responseCachePlugin is not a function
    at startApolloServer (/home/agit/Appety/bon-appety-graphql/app.js:55:7)
    at Object.<anonymous> (/home/agit/Appety/bon-appety-graphql/app.js:76:1)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47
(node:2749) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2749) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

my package.json

"dependencies": {
    "@graphql-tools/schema": "^8.3.1",
    "@graphql-tools/utils": "^8.5.3",
    "apollo-server-cache-redis": "^3.3.0",
    "apollo-server-core": "^3.5.0",
    "apollo-server-express": "^3.5.0",
    "apollo-server-plugin-response-cache": "^3.4.0",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.4",
    "crypto": "^1.0.1",
    "csvjson": "^5.1.0",
    "csvtojson": "^2.0.8",
    "dayjs": "^1.10.7",
    "ejs": "^2.6.1",
    "exceljs": "^4.2.0",
    "express": "^4.17.1",
    "firebase-admin": "^10.0.0",
    "geo-tz": "^4.0.1",
    "googleapis": "^66.0.0",
    "graphql": "^16.0.1",
    "graphql-upload": "^12.0.0",
    "http-errors": "^1.7.0",
    "ioredis": "^4.14.1",
    "jsonwebtoken": "^8.3.0",
    "knex": "^0.95.14",
    "lodash": "^4.17.11",
    "log-to-file": "^1.3.0",
    "moment": "^2.22.2",
    "moment-timezone": "^0.5.21",
    "morgan": "^1.9.1",
    "nanoid": "^3.1.22",
    "node-schedule": "^1.3.2",
    "numeral": "^2.0.6",
    "objection": "^3.0.0",
    "path": "^0.12.7",
    "pg": "^8.7.1",
    "randomstring": "^1.1.5",
    "request": "^2.88.0",
    "rxjs": "^6.4.0",
    "rxjs-compat": "^6.4.0",
    "sharp": "^0.22.0",
    "socket.io": "^3.0.5",
    "uuid": "^3.3.2",
    "validator": "^10.7.0",
    "wkx": "^0.4.6",
    "zxcvbn": "^4.4.2"
  }

before it when i use apollo server version 2, caching with redis its working fine. after migrate to version 3 i go issue.

i appreciate any help, thank you.

glasser commented 2 years ago

This looks like the same issue I closed at #6007.

It seems like perhaps the way we publish this particular package doesn't work well with some particular JS build system. However, without a complete and minimal reproduction that shows how you are building your app, we can't help debug.

wbruno commented 2 years ago

little fix:

const responseCachePlugin = require('apollo-server-plugin-response-cache').default
agitanggriawan commented 2 years ago

i already tried with your suggestion, server can run, but when i'm try to request query the result not stored to redis, maybe there some bug, miss configuration or something. i have no idea

blomm commented 2 years ago

also seems to work plugins: [(responseCachePlugin as any).default() as any],