26 lines
772 B
TypeScript
26 lines
772 B
TypeScript
import { checkAccess } from '../cognito/access-control';
|
|
import { CategoryAPI } from '../datasources/category-api';
|
|
import { ProductAPI } from '../datasources/product-api';
|
|
|
|
const Category = {
|
|
async products({ id }, _args, { dataSources, auth }) {
|
|
checkAccess(['products.read'], auth);
|
|
return (<ProductAPI>dataSources.productApi).getCategoryProducts(id);
|
|
},
|
|
};
|
|
|
|
async function getCategories(_, _args, { dataSources }) {
|
|
return (<CategoryAPI>dataSources.categoryApi).getCategories();
|
|
}
|
|
|
|
async function getCategory(_, { id }, { dataSources }) {
|
|
return (<CategoryAPI>dataSources.categoryApi).getCategoryById(id);
|
|
}
|
|
|
|
export const categoryTypeDefs = { Category };
|
|
|
|
export const categoryQueryTypeDefs = {
|
|
categories: getCategories,
|
|
category: getCategory,
|
|
};
|