Add keywords and product types

This commit is contained in:
Niklas Fondberg
2021-07-07 16:16:58 +02:00
parent 512ebf89f5
commit 267bc4f1c9
11 changed files with 262 additions and 53 deletions
+3
View File
@@ -3,17 +3,20 @@ 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';
import { keywordsQueryTypeDefs, keywordTypeDefs } from './keywords-resolver';
const resolvers = {
Query: {
...orderQueryTypeDefs,
...productQueryTypeDefs,
...designerQueryTypeDefs,
...categoryQueryTypeDefs,
...keywordsQueryTypeDefs,
},
...orderTypeDefs,
...productTypeDefs,
...designerTypeDefs,
...categoryTypeDefs,
...keywordTypeDefs,
DateTime: DateTimeResolver,
Date: DateResolver,
JSON: JSONResolver,
+24
View File
@@ -0,0 +1,24 @@
import { IResolverObject } from 'graphql-tools';
import { KeywordAPI } from '../datasources/keyword-api';
import { ProductAPI } from '../datasources/product-api';
const Keyword: IResolverObject = {
async products({ id }, _args, { dataSources }) {
return (<ProductAPI>dataSources.productApi).getKeywordProducts(id);
},
};
async function getKeywords(_, _args, { dataSources }) {
return (<KeywordAPI>dataSources.keywordApi).getKeywords();
}
async function getKeyword(_, { id }, { dataSources }) {
return (<KeywordAPI>dataSources.keywordApi).getKeywordById(id);
}
export const keywordTypeDefs = { Keyword };
export const keywordsQueryTypeDefs = {
keywords: getKeywords,
keyword: getKeyword,
};
+5
View File
@@ -5,6 +5,8 @@ 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';
const ProductBlacklist: IResolverObject = {
async market(parent, _args, { dataSources }) {
@@ -20,6 +22,9 @@ const Product: IResolverObject = {
async designer({ designerId }, args, { dataSources }) {
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);
},