mirror of
https://github.com/directus/directus.git
synced 2026-01-10 06:38:12 -05:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { Router } from 'express';
|
|
import { parseGraphQL } from '../middleware/graphql.js';
|
|
import { respond } from '../middleware/respond.js';
|
|
import { GraphQLService } from '../services/graphql/index.js';
|
|
import asyncHandler from '../utils/async-handler.js';
|
|
|
|
const router = Router();
|
|
|
|
router.use(
|
|
'/system',
|
|
parseGraphQL,
|
|
asyncHandler(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,
|
|
asyncHandler(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,
|
|
);
|
|
|
|
export default router;
|