UNPKG

@quell/server

Version:

Quell is an open-source NPM package providing a light-weight caching layer implementation and cache invalidation for GraphQL responses on both the client- and server-side. Use Quell to prevent redundant client-side API requests and to minimize costly serv

2 lines 1.37 kB
export declare const serverTemplate = "import express, { Request, Response, NextFunction } from 'express';\nimport { quellCache } from '../../quell-config';\nimport { schema, resolvers } from './schema/example-schema';\nimport dotenv from 'dotenv';\n\n// Load environment variables\ndotenv.config();\n\nconst app = express();\n\nconst PORT = process.env.PORT || 4000;\n\n// Apply Quell caching middleware\napp.use(\n \"/graphql\",\n // clearElapsedTime,\n // quellCache.rateLimiter as any,\n // quellCache.costLimit as any,\n // quellCache.depthLimit as any,\n quellCache.query as any,\n (_req: Request, res: Response): void => {\n try {\n res.status(200).json({ queryResponse: res.locals });\n } catch (error) {\n console.error(\"Error in GraphQL endpoint:\", error);\n res.status(500).json({ error: \"Internal server error\" });\n }\n }\n);\n\n// Add an endpoint to clear the cache\napp.get('/clear-cache', quellCache.clearCache, (req, res) => {\n res.send('Cache cleared successfully');\n});\n\napp.listen(PORT, () => {\n console.log(`\uD83D\uDE80 Server running on http://localhost:${PORT}/graphql`);\n console.log(`\uD83D\uDCCA GraphiQL available at http://localhost:${PORT}/graphql`);\n console.log(`\uD83D\uDDD1\uFE0F Clear cache at http://localhost:${PORT}/clear-cache`);\n});\n"; //# sourceMappingURL=server.template.d.ts.map