Added designers
This commit is contained in:
@@ -2,9 +2,9 @@ import { GraphQLScalarType } from 'graphql';
|
||||
import { Kind } from 'graphql/language';
|
||||
|
||||
// possible switch to https://github.com/Urigo/graphql-scalars
|
||||
export const DateTimeScalar = new GraphQLScalarType({
|
||||
const DateTimeScalar = new GraphQLScalarType({
|
||||
name: 'DateTime',
|
||||
description: 'Date custom scalar type',
|
||||
description: 'Date time custom scalar type',
|
||||
parseValue(value) {
|
||||
return new Date(value); // value from the client
|
||||
},
|
||||
@@ -18,3 +18,26 @@ export const DateTimeScalar = new GraphQLScalarType({
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
const DateScalar = new GraphQLScalarType({
|
||||
name: 'DateTime',
|
||||
description: 'Date custom scalar type',
|
||||
parseValue(value) {
|
||||
console.log('FROM CLIENT:', value);
|
||||
return new Date(value); // value from the client
|
||||
},
|
||||
serialize(value) {
|
||||
return new Date(value).toISOString().split('T')[0]; // value sent to the client
|
||||
},
|
||||
parseLiteral(ast) {
|
||||
if (ast.kind === Kind.INT) {
|
||||
return parseInt(ast.value, 10); // ast value is always in string format
|
||||
}
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
export const CustomTypes = {
|
||||
DateTime: DateTimeScalar,
|
||||
Date: DateScalar,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { DesignerAPI } from '../datasources/designer-api';
|
||||
import { OrderAPI } from '../datasources/order-api';
|
||||
import { FilterInput } from '../datasources/types';
|
||||
|
||||
const Designer: IResolverObject = {
|
||||
async orderRows({ id }, args: FilterInput, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getOrderRowsByDesignerId(
|
||||
id,
|
||||
args.filter,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
async function getDesigners(_, { limit }, { dataSources }) {
|
||||
return (<DesignerAPI>dataSources.designerApi).getDesigners(limit);
|
||||
}
|
||||
|
||||
async function getDesigner(_, { id }, { dataSources }) {
|
||||
return (<DesignerAPI>dataSources.designerApi).getDesignerById(id);
|
||||
}
|
||||
|
||||
export const designerTypeDefs = { Designer };
|
||||
|
||||
export const designerQueryTypeDefs = {
|
||||
designers: getDesigners,
|
||||
designer: getDesigner,
|
||||
};
|
||||
+10
-4
@@ -1,12 +1,18 @@
|
||||
import { orderQueryTypeDefs, orderTypeDefs } from './orders-resolver';
|
||||
import { productQueryTypeDefs, productTypeDefs } from './products-resolver';
|
||||
import { DateTimeScalar } from './datetime-type';
|
||||
|
||||
import { designerQueryTypeDefs, designerTypeDefs } from './designers-resolver';
|
||||
import { DateTimeResolver, DateResolver } from 'graphql-scalars';
|
||||
const resolvers = {
|
||||
Query: { ...orderQueryTypeDefs, ...productQueryTypeDefs },
|
||||
DateTime: DateTimeScalar,
|
||||
Query: {
|
||||
...orderQueryTypeDefs,
|
||||
...productQueryTypeDefs,
|
||||
...designerQueryTypeDefs,
|
||||
},
|
||||
...orderTypeDefs,
|
||||
...productTypeDefs,
|
||||
...designerTypeDefs,
|
||||
DateTime: DateTimeResolver,
|
||||
Date: DateResolver,
|
||||
};
|
||||
|
||||
export default resolvers;
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { OrderAPI } from '../datasources/order-api';
|
||||
import { FilterInput } from '../datasources/types';
|
||||
|
||||
const ContactInformation: IResolverObject = {
|
||||
// (parent, args, ctx, info)
|
||||
async address({ addressId }, args, { dataSources }) {
|
||||
return dataSources.orderApi.getAddress(addressId);
|
||||
return (<OrderAPI>dataSources.orderApi).getAddress(addressId);
|
||||
},
|
||||
};
|
||||
|
||||
const Order: IResolverObject = {
|
||||
async rows({ id }, args, { dataSources }) {
|
||||
return dataSources.orderApi.getOrderRows(id);
|
||||
return (<OrderAPI>dataSources.orderApi).getOrderRowsByOrderId(id);
|
||||
},
|
||||
async marketObject({ market }, args, { dataSources }) {
|
||||
return dataSources.orderApi.getMarketByName(market);
|
||||
return (<OrderAPI>dataSources.orderApi).getMarketByName(market);
|
||||
},
|
||||
};
|
||||
|
||||
const OrderRow: IResolverObject = {
|
||||
async order(parent, args, { dataSources }) {
|
||||
return dataSources.orderApi.getOrder(parent.orderId);
|
||||
return (<OrderAPI>dataSources.orderApi).getOrderById(parent.orderId);
|
||||
},
|
||||
};
|
||||
|
||||
async function getOrders(_, __, { dataSources }) {
|
||||
return dataSources.orderApi.getOrders();
|
||||
async function getOrders(_, args: FilterInput, { dataSources }) {
|
||||
return (<OrderAPI>dataSources.orderApi).getOrders(args.filter);
|
||||
}
|
||||
|
||||
async function getOrder(_, { id }, { dataSources }) {
|
||||
return dataSources.orderApi.getOrder(id);
|
||||
return (<OrderAPI>dataSources.orderApi).getOrderById(id);
|
||||
}
|
||||
|
||||
export const orderTypeDefs = {
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
// (parent, args, ctx, info)
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
import { OrderAPI } from '../datasources/order-api';
|
||||
import { ProductAPI } from '../datasources/product-api';
|
||||
|
||||
const ProductBlacklist: IResolverObject = {
|
||||
async market(parent, args, { dataSources }) {
|
||||
return dataSources.orderApi.getMarketById(parent.marketId);
|
||||
return (<OrderAPI>dataSources.orderApi).getMarketById(parent.marketId);
|
||||
},
|
||||
};
|
||||
|
||||
const Product: IResolverObject = {
|
||||
async categories({ id }, args, { dataSources }) {
|
||||
return dataSources.productApi.getCategories(id);
|
||||
return (<ProductAPI>dataSources.productApi).getCategories(id);
|
||||
},
|
||||
async designer({ designerId }, args, { dataSources }) {
|
||||
return dataSources.designerApi.getDesignerById(designerId);
|
||||
},
|
||||
};
|
||||
|
||||
async function getProducts(_, { limit, visible, browsable }, { dataSources }) {
|
||||
return dataSources.productApi.getProducts(limit, visible, browsable);
|
||||
return (<ProductAPI>dataSources.productApi).getProducts(
|
||||
limit,
|
||||
visible,
|
||||
browsable,
|
||||
);
|
||||
}
|
||||
|
||||
async function getProduct(_, { id }, { dataSources }) {
|
||||
return dataSources.productApi.getProduct(id);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(id);
|
||||
}
|
||||
|
||||
export const productTypeDefs = {
|
||||
|
||||
Reference in New Issue
Block a user