feat: add caching!!
This commit is contained in:
		
							parent
							
								
									8ccb88558f
								
							
						
					
					
						commit
						38a2fe8215
					
				|  | @ -28,6 +28,7 @@ | |||
|   }, | ||||
|   "dependencies": { | ||||
|     "@floating-ui/react-dom": "^0.7.2", | ||||
|     "@graphql-yoga/plugin-response-cache": "^1.0.0-next.10", | ||||
|     "@pothos/core": "^3.22.8", | ||||
|     "@pothos/plugin-prisma": "^3.35.6", | ||||
|     "@pothos/plugin-relay": "^3.28.6", | ||||
|  |  | |||
|  | @ -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
 | ||||
| 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; | ||||
|   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; | ||||
|  |  | |||
							
								
								
									
										19
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								yarn.lock
									
									
									
									
									
								
							|  | @ -819,6 +819,16 @@ | |||
|     lru-cache "^6.0.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": | ||||
|   version "3.0.0" | ||||
|   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" | ||||
|   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": | ||||
|   version "3.0.0-next.0" | ||||
|   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" | ||||
|     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" | ||||
|   resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" | ||||
|   integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user