Add product
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { GraphQLScalarType } from 'graphql';
|
||||
import { Kind } from 'graphql/language';
|
||||
|
||||
// possible switch to https://github.com/Urigo/graphql-scalars
|
||||
export const DateTimeScalar = new GraphQLScalarType({
|
||||
name: 'DateTime',
|
||||
description: 'Date custom scalar type',
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import orders, { ContactInformation, Order } from './orders-resolver';
|
||||
import products from './products-resolver';
|
||||
import { orderQueryTypeDefs, orderTypeDefs } from './orders-resolver';
|
||||
import { productQueryTypeDefs, productTypeDefs } from './products-resolver';
|
||||
import { DateTimeScalar } from './datetime-type';
|
||||
|
||||
const resolvers = {
|
||||
Query: { ...orders, ...products },
|
||||
Query: { ...orderQueryTypeDefs, ...productQueryTypeDefs },
|
||||
DateTime: DateTimeScalar,
|
||||
ContactInformation,
|
||||
Order,
|
||||
...orderTypeDefs,
|
||||
...productTypeDefs,
|
||||
};
|
||||
|
||||
export default resolvers;
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
|
||||
export const ContactInformation: IResolverObject = {
|
||||
const ContactInformation: IResolverObject = {
|
||||
// (parent, args, ctx, info)
|
||||
async address({ addressId }, args, { dataSources }) {
|
||||
return dataSources.orderApi.getAddress(addressId);
|
||||
},
|
||||
};
|
||||
|
||||
export const Order: IResolverObject = {
|
||||
const Order: IResolverObject = {
|
||||
async rows({ id }, args, { dataSources }) {
|
||||
return dataSources.orderApi.getOrderRows(id);
|
||||
},
|
||||
async marketObject({ market }, args, { dataSources }) {
|
||||
return dataSources.orderApi.getMarketByName(market);
|
||||
},
|
||||
};
|
||||
|
||||
const OrderRow: IResolverObject = {
|
||||
async order(parent, args, { dataSources }) {
|
||||
return dataSources.orderApi.getOrder(parent.orderId);
|
||||
},
|
||||
};
|
||||
|
||||
async function getOrders(_, __, { dataSources }) {
|
||||
@@ -21,9 +30,13 @@ async function getOrder(_, { id }, { dataSources }) {
|
||||
return dataSources.orderApi.getOrder(id);
|
||||
}
|
||||
|
||||
const orders = {
|
||||
export const orderTypeDefs = {
|
||||
ContactInformation,
|
||||
Order,
|
||||
OrderRow,
|
||||
};
|
||||
|
||||
export const orderQueryTypeDefs = {
|
||||
orders: getOrders,
|
||||
order: getOrder,
|
||||
};
|
||||
|
||||
export default orders;
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
// (parent, args, ctx, info)
|
||||
const products = {
|
||||
products: (_, { limit, visible, browsable }, { dataSources }) =>
|
||||
dataSources.productApi.getProducts(limit, visible, browsable),
|
||||
import { IResolverObject } from 'graphql-tools';
|
||||
|
||||
const ProductBlacklist: IResolverObject = {
|
||||
async market(parent, args, { dataSources }) {
|
||||
return dataSources.orderApi.getMarketById(parent.marketId);
|
||||
},
|
||||
};
|
||||
|
||||
export default products;
|
||||
async function getProducts(_, { limit, visible, browsable }, { dataSources }) {
|
||||
return dataSources.productApi.getProducts(limit, visible, browsable);
|
||||
}
|
||||
|
||||
async function getProduct(_, { id }, { dataSources }) {
|
||||
return dataSources.productApi.getProduct(id);
|
||||
}
|
||||
|
||||
export const productTypeDefs = {
|
||||
ProductBlacklist,
|
||||
};
|
||||
|
||||
export const productQueryTypeDefs = {
|
||||
products: getProducts,
|
||||
product: getProduct,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user