Added product admin features
This commit is contained in:
@@ -16,7 +16,7 @@ async function getDesigners(_, { limit }, { dataSources }) {
|
||||
return (<DesignerAPI>dataSources.designerApi).getDesigners(limit);
|
||||
}
|
||||
|
||||
async function getDesigner(_, { id }, { dataSources }) {
|
||||
async function getDesigner(parent, { id }, { dataSources }) {
|
||||
return (<DesignerAPI>dataSources.designerApi).getDesignerById(id);
|
||||
}
|
||||
|
||||
|
||||
+16
-2
@@ -1,9 +1,16 @@
|
||||
import { orderQueryTypeDefs, orderTypeDefs } from './orders-resolver';
|
||||
import { productQueryTypeDefs, productTypeDefs } from './products-resolver';
|
||||
import {
|
||||
productQueryTypeDefs,
|
||||
productTypeDefs,
|
||||
productMutationTypeDefs,
|
||||
} from './products-resolver';
|
||||
import { designerQueryTypeDefs, designerTypeDefs } from './designers-resolver';
|
||||
import { categoryQueryTypeDefs, categoryTypeDefs } from './categories-resolver';
|
||||
import { DateTimeResolver, DateResolver, JSONResolver } from 'graphql-scalars';
|
||||
import { keywordsQueryTypeDefs, keywordTypeDefs } from './keywords-resolver';
|
||||
import { marketsQueryTypeDefs, marketTypeDefs } from './markets-resolver';
|
||||
|
||||
import { DateTimeResolver, DateResolver, JSONResolver } from 'graphql-scalars';
|
||||
import { interiorsQueryTypeDefs, interiorTypeDefs } from './interiors-resolver';
|
||||
const resolvers = {
|
||||
Query: {
|
||||
...orderQueryTypeDefs,
|
||||
@@ -11,12 +18,19 @@ const resolvers = {
|
||||
...designerQueryTypeDefs,
|
||||
...categoryQueryTypeDefs,
|
||||
...keywordsQueryTypeDefs,
|
||||
...marketsQueryTypeDefs,
|
||||
...interiorsQueryTypeDefs,
|
||||
},
|
||||
Mutation: {
|
||||
...productMutationTypeDefs,
|
||||
},
|
||||
...orderTypeDefs,
|
||||
...productTypeDefs,
|
||||
...designerTypeDefs,
|
||||
...categoryTypeDefs,
|
||||
...keywordTypeDefs,
|
||||
...marketTypeDefs,
|
||||
...interiorTypeDefs,
|
||||
DateTime: DateTimeResolver,
|
||||
Date: DateResolver,
|
||||
JSON: JSONResolver,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { InteriorAPI } from '../datasources/interior-api';
|
||||
import { InteriorsFilterInput } from '../types/interior-types';
|
||||
|
||||
const Interior: IResolverObject = {};
|
||||
|
||||
async function getInteriors(_, args: InteriorsFilterInput, { dataSources }) {
|
||||
return (<InteriorAPI>dataSources.interiorApi).getInteriors(args.filter);
|
||||
}
|
||||
|
||||
export const interiorTypeDefs = { Interior };
|
||||
|
||||
export const interiorsQueryTypeDefs = {
|
||||
interiors: getInteriors,
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { MarketAPI } from '../datasources/market-api';
|
||||
|
||||
const Market: IResolverObject = {};
|
||||
|
||||
async function getMarkets(_, _args, { dataSources }) {
|
||||
return (<MarketAPI>dataSources.marketApi).getMarkets();
|
||||
}
|
||||
|
||||
async function getMarket(_, { name }, { dataSources }) {
|
||||
return (<MarketAPI>dataSources.marketApi).getMarketByName(name);
|
||||
}
|
||||
|
||||
export const marketTypeDefs = { Market };
|
||||
|
||||
export const marketsQueryTypeDefs = {
|
||||
markets: getMarkets,
|
||||
market: getMarket,
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { MarketAPI } from '../datasources/market-api';
|
||||
import { OrderAPI } from '../datasources/order-api';
|
||||
import { FilterInput } from '../types/types';
|
||||
|
||||
@@ -14,7 +15,7 @@ const Order: IResolverObject = {
|
||||
return (<OrderAPI>dataSources.orderApi).getOrderRowsByOrderId(id);
|
||||
},
|
||||
async market({ market }, _args, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getMarketByName(market);
|
||||
return (<MarketAPI>dataSources.marketApi).getMarketByName(market);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
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';
|
||||
import { KeywordAPI } from '../datasources/keyword-api';
|
||||
import { Keyword } from '../types/keyword-types';
|
||||
import { MarketAPI } from '../datasources/market-api';
|
||||
import { InteriorAPI } from '../datasources/interior-api';
|
||||
|
||||
const ProductBlacklist: IResolverObject = {
|
||||
async market(parent, _args, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getMarketById(parent.marketId);
|
||||
return (<MarketAPI>dataSources.marketApi).getMarketById(parent.marketId);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -20,24 +20,22 @@ const Product: IResolverObject = {
|
||||
return (<CategoryAPI>dataSources.categoryApi).getProductCategories(id);
|
||||
},
|
||||
async designer({ designerId }, args, { dataSources }) {
|
||||
if (!designerId) {
|
||||
return null;
|
||||
}
|
||||
return dataSources.designerApi.getDesignerById(designerId);
|
||||
},
|
||||
async keywords({ id }, _args, { dataSources }): Promise<Array<Keyword>> {
|
||||
return (<KeywordAPI>dataSources.keywordApi).getProductKeywords(id);
|
||||
},
|
||||
async api1json({ id }, _args, { dataSources }): Promise<JSON> {
|
||||
return dataSources.api1.getProduct(id);
|
||||
async related({ id }, _args, { dataSources }) {
|
||||
return (<ProductAPI>dataSources.productApi).getRelatedProducts(id);
|
||||
},
|
||||
};
|
||||
|
||||
const PrintProduct: IResolverObject = {
|
||||
async price({ id }, { market, width, height, sku }, { dataSources }) {
|
||||
return (<Api2DataSource>dataSources.api2).getPrice(
|
||||
market,
|
||||
width,
|
||||
height,
|
||||
sku,
|
||||
);
|
||||
async interiors({ id }, _args, { dataSources }) {
|
||||
return (<InteriorAPI>dataSources.interiorApi).getPrintProductInteriors(id);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -67,3 +65,11 @@ export const productQueryTypeDefs = {
|
||||
products: getProducts,
|
||||
product: getProduct,
|
||||
};
|
||||
|
||||
// Mutations below
|
||||
|
||||
export const productMutationTypeDefs = {
|
||||
addKeyword(_, { productId, keywordId }, { dataSources }) {
|
||||
return { result: 'OK' };
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user