feat: add caching!!

This commit is contained in:
NunoSempere 2022-11-09 21:54:08 +00:00
parent 8ccb88558f
commit 38a2fe8215
3 changed files with 35 additions and 6 deletions

View File

@ -28,6 +28,7 @@
}, },
"dependencies": { "dependencies": {
"@floating-ui/react-dom": "^0.7.2", "@floating-ui/react-dom": "^0.7.2",
"@graphql-yoga/plugin-response-cache": "^1.0.0-next.10",
"@pothos/core": "^3.22.8", "@pothos/core": "^3.22.8",
"@pothos/plugin-prisma": "^3.35.6", "@pothos/plugin-prisma": "^3.35.6",
"@pothos/plugin-relay": "^3.28.6", "@pothos/plugin-relay": "^3.28.6",

View File

@ -1,13 +1,24 @@
import { NextApiRequest, NextApiResponse } from "next"; import {NextApiRequest, NextApiResponse} from "next";
// apollo-server-micro is problematic since v3, see https://github.com/apollographql/apollo-server/issues/5547, so we use graphql-yoga instead // apollo-server-micro is problematic since v3, see https://github.com/apollographql/apollo-server/issues/5547, so we use graphql-yoga instead
import { createYoga } from "graphql-yoga"; import {createYoga} from "graphql-yoga";
import {useResponseCache} from '@graphql-yoga/plugin-response-cache'
import { schema } from "../../graphql/schema"; import {schema} from "../../graphql/schema";
const server = createYoga<{ const server = createYoga < {
req: NextApiRequest; req: NextApiRequest;
res: NextApiResponse; res: NextApiResponse;
}>({ schema }); } > ({
schema,
graphqlEndpoint: '/api/graphql',
plugins: [useResponseCache(
{ // global cache
session: () => null,
ttl: 2 * 60 * 60 * 1000,
// ^ 2h * 60 mins per hour, 60 seconds per min 1000 miliseconds per second
}
)]
});
export default server; export default server;

View File

@ -819,6 +819,16 @@
lru-cache "^6.0.0" lru-cache "^6.0.0"
tslib "^2.4.0" tslib "^2.4.0"
"@envelop/response-cache@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@envelop/response-cache/-/response-cache-4.0.3.tgz#3099c7d7db61d999490105ffd2333753c7fe05cb"
integrity sha512-5podyYKo2VzGnlPYYTbC6ivOdJ1TbzX2zOunOhVbnSbY2tAKwo+9kkpi7e2hfe4eUbpZTnuh05gpTZXcPPdo+A==
dependencies:
"@graphql-tools/utils" "^8.8.0"
fast-json-stable-stringify "^2.1.0"
lru-cache "^6.0.0"
tslib "^2.4.0"
"@envelop/types@3.0.0": "@envelop/types@3.0.0":
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/@envelop/types/-/types-3.0.0.tgz#33795a7826a541eff00c0d6fb4eab9c35fef784b" resolved "https://registry.yarnpkg.com/@envelop/types/-/types-3.0.0.tgz#33795a7826a541eff00c0d6fb4eab9c35fef784b"
@ -1320,6 +1330,13 @@
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.1.tgz#076d78ce99822258cf813ecc1e7fa460fa74d052" resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.1.tgz#076d78ce99822258cf813ecc1e7fa460fa74d052"
integrity sha512-NQ17ii0rK1b34VZonlmT2QMJFI70m0TRwbknO/ihlbatXyaktDhN/98vBiUU6kNBPljqGqyIrl2T4nY2RpFANg== integrity sha512-NQ17ii0rK1b34VZonlmT2QMJFI70m0TRwbknO/ihlbatXyaktDhN/98vBiUU6kNBPljqGqyIrl2T4nY2RpFANg==
"@graphql-yoga/plugin-response-cache@^1.0.0-next.10":
version "1.0.0-next.10"
resolved "https://registry.yarnpkg.com/@graphql-yoga/plugin-response-cache/-/plugin-response-cache-1.0.0-next.10.tgz#a88efe42fe51791f90282aa5423ef790b8591d16"
integrity sha512-3NMi3SIX2W4yhsGrPNMedyoa44b0gE9a5TPHWe29E/bvfrHZ1H9paBVN78dQIo8YRBenUTCBhTkZgoa79NvnKw==
dependencies:
"@envelop/response-cache" "4.0.3"
"@graphql-yoga/subscription@^3.0.0-next.0": "@graphql-yoga/subscription@^3.0.0-next.0":
version "3.0.0-next.0" version "3.0.0-next.0"
resolved "https://registry.yarnpkg.com/@graphql-yoga/subscription/-/subscription-3.0.0-next.0.tgz#fce94b540ec8837c7667e24b556b70553ccb558b" resolved "https://registry.yarnpkg.com/@graphql-yoga/subscription/-/subscription-3.0.0-next.0.tgz#fce94b540ec8837c7667e24b556b70553ccb558b"
@ -4262,7 +4279,7 @@ fast-glob@^3.2.12, fast-glob@^3.2.9:
merge2 "^1.3.0" merge2 "^1.3.0"
micromatch "^4.0.4" micromatch "^4.0.4"
fast-json-stable-stringify@^2.0.0: fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==