* print defaults in printproducts * Add default to printproduct mutation * added insertDefaults when changing productgroup * fixed bug for square in square * cleanup, and tests for calculations * small fixes, added return values for update
104 lines
3.0 KiB
TypeScript
104 lines
3.0 KiB
TypeScript
import dotenv from 'dotenv';
|
|
dotenv.config();
|
|
|
|
import { ApolloServer, AuthenticationError } from 'apollo-server';
|
|
import knexStringcase from 'knex-stringcase';
|
|
import { dbConfig } from './config';
|
|
|
|
import resolvers from './resolvers';
|
|
import { OrderAPI } from './datasources/order-api';
|
|
import { ProductAPI } from './datasources/product-api';
|
|
import { DesignerAPI } from './datasources/designer-api';
|
|
import { CategoryAPI } from './datasources/category-api';
|
|
import { KeywordAPI } from './datasources/keyword-api';
|
|
import { MarketLocaleAPI } from './datasources/market-locale-api';
|
|
import { ImageServerApi } from './datasources/imageserver-api';
|
|
import { InteriorAPI } from './datasources/interior-api';
|
|
|
|
import { verifyToken } from './cognito/cognito-client';
|
|
import { readFileSync } from 'fs';
|
|
import { InteriorsLambdaAPI } from './datasources/interiors-lambda-api';
|
|
import { TextsAPI } from './datasources/texts-api';
|
|
import { PrintProductDefaultsAPI } from './datasources/printproduct-defaults-api';
|
|
|
|
const path = require('path');
|
|
const typeDefs = readFileSync(
|
|
path.join(__dirname, './schema.graphql'),
|
|
).toString('utf-8');
|
|
|
|
// Converts column names to CamelCase
|
|
const knexConfig = knexStringcase(dbConfig);
|
|
|
|
// set up any dataSources our resolvers need
|
|
const marketLocaleApi = new MarketLocaleAPI(knexConfig);
|
|
const textsApi = new TextsAPI(knexConfig, marketLocaleApi);
|
|
const categoryApi = new CategoryAPI(knexConfig);
|
|
const designerApi = new DesignerAPI(knexConfig);
|
|
const imageServerApi = new ImageServerApi();
|
|
const interiorsLambdaApi = new InteriorsLambdaAPI();
|
|
const interiorApi = new InteriorAPI(knexConfig, imageServerApi);
|
|
const printProductDefaultsApi = new PrintProductDefaultsAPI(knexConfig);
|
|
const keywordApi = new KeywordAPI(knexConfig);
|
|
const orderApi = new OrderAPI(knexConfig);
|
|
const productApi = new ProductAPI(
|
|
knexConfig,
|
|
textsApi,
|
|
printProductDefaultsApi,
|
|
);
|
|
|
|
const dataSources = () => ({
|
|
categoryApi,
|
|
designerApi,
|
|
interiorApi,
|
|
printProductDefaultsApi,
|
|
interiorsLambdaApi,
|
|
imageServerApi,
|
|
keywordApi,
|
|
marketLocaleApi,
|
|
orderApi,
|
|
productApi,
|
|
});
|
|
|
|
const context = async ({ req }) => {
|
|
if (process.env.NODE_ENV == 'test') {
|
|
return { auth: { userName: 'testuser' } };
|
|
}
|
|
|
|
const authHeader = req.headers.authorization || '';
|
|
if (authHeader.startsWith('Bearer ')) {
|
|
const token = authHeader.substring(7, authHeader.length);
|
|
const res = await verifyToken({ token });
|
|
if (res.isValid) {
|
|
return { auth: res };
|
|
}
|
|
} else if (
|
|
process.env.NODE_ENV === 'development' &&
|
|
authHeader == 'Basic ZGV2OnB2N1VmYSFiZVAzeGk='
|
|
) {
|
|
return {
|
|
auth: {
|
|
userName: 'testuser',
|
|
isValid: true,
|
|
accessToken: null,
|
|
idToken: null,
|
|
},
|
|
};
|
|
}
|
|
throw new AuthenticationError('Not authorized');
|
|
};
|
|
|
|
async function main() {
|
|
const server = new ApolloServer({
|
|
typeDefs,
|
|
resolvers,
|
|
dataSources,
|
|
context,
|
|
introspection: true,
|
|
});
|
|
|
|
await server.listen();
|
|
|
|
console.log('Server is running on http://localhost:4000');
|
|
}
|
|
main();
|