Add product

This commit is contained in:
Niklas Fondberg
2021-04-08 15:09:31 +02:00
parent e0f629d54d
commit f60a51a94b
11 changed files with 184 additions and 171 deletions
+1
View File
@@ -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',
+5 -5
View File
@@ -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;
+18 -5
View File
@@ -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;
+22 -4
View File
@@ -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,
};