diff --git a/package.json b/package.json index d4d877b..490c6de 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "debug": "ts-node-dev --inspect --respawn --transpileOnly src/bootstrap.ts" }, "dependencies": { - "apollo-server": "^2.9.3", "apollo-server-express": "^2.9.4", "argon2": "^0.24.1", "dotenv": "^8.1.0", diff --git a/src/server/UserResolver.spec.ts b/src/server/UserResolver.spec.ts index a7f8725..cf0a319 100644 --- a/src/server/UserResolver.spec.ts +++ b/src/server/UserResolver.spec.ts @@ -1,4 +1,4 @@ -import { gql } from "apollo-server" +import { gql } from "apollo-server-express" import { Request, Response } from "express" import { createConnection, getConnection } from "typeorm" import { callSchema } from "./schema" diff --git a/src/server/testing.ts b/src/server/testing.ts index f7f7b57..ba05d99 100644 --- a/src/server/testing.ts +++ b/src/server/testing.ts @@ -1,50 +1,50 @@ -import { ConnectionOptions } from "typeorm" -import { - initializeTransactionalContext, - patchTypeORMRepositoryWithBaseRepository, - Propagation, - Transactional, -} from "typeorm-transactional-cls-hooked" -import { connectionOptions } from "./connection" - -export const testingConnectionOptions = () => { - const database = process.env.DB_NAME_TESING as string - - return { ...connectionOptions(), database } as ConnectionOptions -} - -export const initializeRollbackTransactions = () => { - initializeTransactionalContext() - patchTypeORMRepositoryWithBaseRepository() -} - -type RunFunction = () => Promise | void - -class RollbackError extends Error { - constructor(message: string) { - super(message) - - this.name = this.constructor.name - } -} - -class TransactionCreator { - @Transactional({ propagation: Propagation.REQUIRED }) - static async run(func: RunFunction) { - await func() - throw new RollbackError(`This is thrown to cause a rollback on the transaction.`) - } -} - -export function runInRollbackTransaction(func: RunFunction) { - return async () => { - try { - await TransactionCreator.run(func) - } catch (e) { - /* istanbul ignore next */ - if (!(e instanceof RollbackError)) { - throw e - } - } - } -} +import { ConnectionOptions } from "typeorm" +import { + initializeTransactionalContext, + patchTypeORMRepositoryWithBaseRepository, + Propagation, + Transactional, +} from "typeorm-transactional-cls-hooked" +import { connectionOptions } from "./connection" + +export const testingConnectionOptions = () => { + const database = process.env.DB_NAME_TESING as string + + return { ...connectionOptions(), database } as ConnectionOptions +} + +export const initializeRollbackTransactions = () => { + initializeTransactionalContext() + patchTypeORMRepositoryWithBaseRepository() +} + +type RunFunction = () => Promise | void + +class RollbackError extends Error { + constructor(message: string) { + super(message) + + this.name = this.constructor.name + } +} + +class TransactionCreator { + @Transactional({ propagation: Propagation.REQUIRED }) + static async run(func: RunFunction) { + await func() + throw new RollbackError(`This is thrown to cause a rollback on the transaction.`) + } +} + +export function runInRollbackTransaction(func: RunFunction) { + return async () => { + try { + await TransactionCreator.run(func) + } catch (e) { + /* istanbul ignore next */ + if (!(e instanceof RollbackError)) { + throw e + } + } + } +}