109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
import { ApolloServer } from '@apollo/server';
|
|
import knexStringcase from 'knex-stringcase';
|
|
import {
|
|
ClaimVerifyResult,
|
|
verifyAuthentication,
|
|
} from './cognito/cognito-client';
|
|
import { dbConfig } from './config';
|
|
import { CategoryAPI } from './datasources/category-api';
|
|
import { CollectionAPI } from './datasources/collection-api';
|
|
import { DesignerAPI } from './datasources/designer-api';
|
|
import { ImageServerApi } from './datasources/imageserver-api';
|
|
import { InteriorAPI } from './datasources/interior-api';
|
|
import { InteriorsLambdaAPI } from './datasources/interiors-lambda-api';
|
|
import { KeywordAPI } from './datasources/keyword-api';
|
|
import { MarketLocaleAPI } from './datasources/market-locale-api';
|
|
import { OrderAPI } from './datasources/order-api';
|
|
import { PrintProductDefaultsAPI } from './datasources/printproduct-defaults-api';
|
|
import { ProductAPI } from './datasources/product-api';
|
|
import { TextsAPI } from './datasources/texts-api';
|
|
import { IncomingMessage } from 'http';
|
|
import { DataSourceOptions, IAuthObject } from './types/types';
|
|
|
|
const knexConfig = knexStringcase(dbConfig);
|
|
|
|
export class ContextValue {
|
|
public req: IncomingMessage;
|
|
public server: ApolloServer<ContextValue>;
|
|
public user: IAuthObject | ClaimVerifyResult;
|
|
public dataSources: {
|
|
marketLocaleApi: MarketLocaleAPI;
|
|
textsApi: TextsAPI;
|
|
categoryApi: CategoryAPI;
|
|
designerApi: DesignerAPI;
|
|
imageServerApi: ImageServerApi;
|
|
interiorsLambdaApi: InteriorsLambdaAPI;
|
|
interiorApi: InteriorAPI;
|
|
printProductDefaultsApi: PrintProductDefaultsAPI;
|
|
keywordApi: KeywordAPI;
|
|
orderApi: OrderAPI;
|
|
productApi: ProductAPI;
|
|
collectionApi: CollectionAPI;
|
|
};
|
|
|
|
constructor({
|
|
req,
|
|
server,
|
|
}: {
|
|
req: IncomingMessage;
|
|
server: ApolloServer<ContextValue>;
|
|
}) {
|
|
this.req = req;
|
|
this.server = server;
|
|
}
|
|
|
|
async process() {
|
|
const { cache } = this.server;
|
|
|
|
// -------------------------------
|
|
// Authentication
|
|
// -------------------------------
|
|
|
|
this.user = await verifyAuthentication(this.req);
|
|
|
|
// -------------------------------
|
|
// DataSources
|
|
// -------------------------------
|
|
|
|
const options: DataSourceOptions = { cache, user: this.user };
|
|
|
|
const marketLocaleApi = new MarketLocaleAPI(options, knexConfig);
|
|
const textsApi = new TextsAPI(options, knexConfig, marketLocaleApi);
|
|
const categoryApi = new CategoryAPI(options, knexConfig);
|
|
const designerApi = new DesignerAPI(options, knexConfig);
|
|
const imageServerApi = new ImageServerApi(options);
|
|
const interiorsLambdaApi = new InteriorsLambdaAPI(options);
|
|
const interiorApi = new InteriorAPI(options, knexConfig, imageServerApi);
|
|
const printProductDefaultsApi = new PrintProductDefaultsAPI(
|
|
options,
|
|
knexConfig,
|
|
);
|
|
const keywordApi = new KeywordAPI(options, knexConfig, textsApi);
|
|
const orderApi = new OrderAPI(options, knexConfig);
|
|
const productApi = new ProductAPI(
|
|
options,
|
|
knexConfig,
|
|
textsApi,
|
|
printProductDefaultsApi,
|
|
);
|
|
const collectionApi = new CollectionAPI(options, knexConfig);
|
|
|
|
this.dataSources = {
|
|
productApi,
|
|
marketLocaleApi,
|
|
textsApi,
|
|
categoryApi,
|
|
designerApi,
|
|
imageServerApi,
|
|
interiorsLambdaApi,
|
|
interiorApi,
|
|
printProductDefaultsApi,
|
|
keywordApi,
|
|
orderApi,
|
|
collectionApi,
|
|
};
|
|
|
|
return this;
|
|
}
|
|
}
|