UNPKG

@directus/api

Version:

Directus is a real-time API and App dashboard for managing SQL database content

34 lines (32 loc) 1.29 kB
import async_handler_default from "../utils/async-handler.js"; import { respond } from "../middleware/respond.js"; import { GraphQLService } from "../services/graphql/index.js"; import is_locked_default from "../middleware/is-locked.js"; import { parseGraphQL } from "../middleware/graphql.js"; import { Router } from "express"; //#region src/controllers/graphql.ts const router = Router(); router.use(is_locked_default("graphql")); router.use("/system", parseGraphQL, async_handler_default(async (req, res, next) => { const service = new GraphQLService({ accountability: req.accountability, schema: req.schema, scope: "system" }); res.locals["payload"] = await service.execute(res.locals["graphqlParams"]); if (res.locals["payload"]?.errors?.length > 0) res.locals["cache"] = false; return next(); }), respond); router.use("/", parseGraphQL, async_handler_default(async (req, res, next) => { const service = new GraphQLService({ accountability: req.accountability, schema: req.schema, scope: "items" }); res.locals["payload"] = await service.execute(res.locals["graphqlParams"]); if (res.locals["payload"]?.errors?.length > 0) res.locals["cache"] = false; return next(); }), respond); var graphql_default = router; //#endregion export { graphql_default as default };