Major refactor
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { CategoryAPI } from '../datasources/category-api';
|
||||
import { ProductAPI } from '../datasources/product-api';
|
||||
|
||||
const Category: IResolverObject = {
|
||||
async products({ id }, _args, { dataSources }) {
|
||||
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,
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { DesignerAPI } from '../datasources/designer-api';
|
||||
import { OrderAPI } from '../datasources/order-api';
|
||||
import { FilterInput } from '../datasources/types';
|
||||
import { FilterInput } from '../types/types';
|
||||
|
||||
const Designer: IResolverObject = {
|
||||
async orderRows({ id }, args: FilterInput, { dataSources }) {
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { orderQueryTypeDefs, orderTypeDefs } from './orders-resolver';
|
||||
import { productQueryTypeDefs, productTypeDefs } from './products-resolver';
|
||||
import { designerQueryTypeDefs, designerTypeDefs } from './designers-resolver';
|
||||
import { categoryQueryTypeDefs, categoryTypeDefs } from './categories-resolver';
|
||||
import { DateTimeResolver, DateResolver, JSONResolver } from 'graphql-scalars';
|
||||
const resolvers = {
|
||||
Query: {
|
||||
...orderQueryTypeDefs,
|
||||
...productQueryTypeDefs,
|
||||
...designerQueryTypeDefs,
|
||||
...categoryQueryTypeDefs,
|
||||
},
|
||||
...orderTypeDefs,
|
||||
...productTypeDefs,
|
||||
...designerTypeDefs,
|
||||
...categoryTypeDefs,
|
||||
DateTime: DateTimeResolver,
|
||||
Date: DateResolver,
|
||||
JSON: JSONResolver,
|
||||
|
||||
@@ -1,31 +1,36 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { OrderAPI } from '../datasources/order-api';
|
||||
import { FilterInput } from '../datasources/types';
|
||||
import { FilterInput } from '../types/types';
|
||||
|
||||
const ContactInformation: IResolverObject = {
|
||||
// (parent, args, ctx, info)
|
||||
async address({ addressId }, args, { dataSources }) {
|
||||
async address({ addressId }, _args, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getAddress(addressId);
|
||||
},
|
||||
};
|
||||
|
||||
const Order: IResolverObject = {
|
||||
async rows({ id }, args, { dataSources }) {
|
||||
async rows({ id }, _args, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getOrderRowsByOrderId(id);
|
||||
},
|
||||
async market({ market }, args, { dataSources }) {
|
||||
async market({ market }, _args, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getMarketByName(market);
|
||||
},
|
||||
};
|
||||
|
||||
const OrderRow: IResolverObject = {
|
||||
async order(parent, args, { dataSources }) {
|
||||
async order(parent, _args, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getOrderById(parent.orderId);
|
||||
},
|
||||
};
|
||||
|
||||
async function getOrders(_, args: FilterInput, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getOrders(args.filter);
|
||||
async function getOrdersResult(_, args: FilterInput, { dataSources }) {
|
||||
const total = (<OrderAPI>dataSources.orderApi).getOrdersTotal(args.filter);
|
||||
const items = (<OrderAPI>dataSources.orderApi).getOrders(args.filter);
|
||||
return {
|
||||
total: total,
|
||||
items: items,
|
||||
};
|
||||
}
|
||||
|
||||
async function getOrder(_, { id }, { dataSources }) {
|
||||
@@ -39,6 +44,6 @@ export const orderTypeDefs = {
|
||||
};
|
||||
|
||||
export const orderQueryTypeDefs = {
|
||||
orders: getOrders,
|
||||
orders: getOrdersResult,
|
||||
order: getOrder,
|
||||
};
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
// (parent, args, ctx, info)
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { Api2DataSource } from '../datasources/api2-datasource';
|
||||
import { OrderAPI } from '../datasources/order-api';
|
||||
import { ProductAPI } from '../datasources/product-api';
|
||||
import { Product } from '../types/product-types';
|
||||
import { CategoryAPI } from '../datasources/category-api';
|
||||
import { Category } from '../types/category-types';
|
||||
|
||||
const ProductBlacklist: IResolverObject = {
|
||||
async market(parent, args, { dataSources }) {
|
||||
async market(parent, _args, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getMarketById(parent.marketId);
|
||||
},
|
||||
};
|
||||
|
||||
const Product: IResolverObject = {
|
||||
async categories({ id }, args, { dataSources }) {
|
||||
return (<ProductAPI>dataSources.productApi).getCategories(id);
|
||||
// (parent, args, ctx, info)
|
||||
async categories({ id }, _args, { dataSources }): Promise<Array<Category>> {
|
||||
return (<CategoryAPI>dataSources.categoryApi).getProductCategories(id);
|
||||
},
|
||||
async designer({ designerId }, args, { dataSources }) {
|
||||
return dataSources.designerApi.getDesignerById(designerId);
|
||||
},
|
||||
async api1json({ id }, _args, { dataSources }): Promise<JSON> {
|
||||
return dataSources.api1.getProduct(id);
|
||||
},
|
||||
};
|
||||
|
||||
const PrintProduct: IResolverObject = {
|
||||
@@ -30,7 +36,11 @@ const PrintProduct: IResolverObject = {
|
||||
},
|
||||
};
|
||||
|
||||
async function getProducts(_, { limit, visible, browsable }, { dataSources }) {
|
||||
async function getProducts(
|
||||
_,
|
||||
{ limit, visible, browsable },
|
||||
{ dataSources },
|
||||
): Promise<Array<Product>> {
|
||||
return (<ProductAPI>dataSources.productApi).getProducts(
|
||||
limit,
|
||||
visible,
|
||||
@@ -38,7 +48,7 @@ async function getProducts(_, { limit, visible, browsable }, { dataSources }) {
|
||||
);
|
||||
}
|
||||
|
||||
async function getProduct(_, { id }, { dataSources }) {
|
||||
async function getProduct(_, { id }, { dataSources }): Promise<Product> {
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user