@ams-pro/apollo-plugin-transaction
v0.0.2
Published
A Plugin for automatic creation of a typeorm transaction per request
Downloads
6
Readme
About The Project
The Plugin is a small plugin for automatic typeorm transactions. All requests are encapsulated into a typeorm transaction and a EntityManager for running database commands is attached to the context.
Getting started
Installation
npm install @ams-pro/apollo-plugin-transaction
or
yarn add @ams-pro/apollo-plugin-transaction
Usage
- Initialize the Plugin
import { TransactionPlugin } from '@ams-pro/apollo-plugin-transaction'; // Setup database connection const server = new ApolloServer({ resolvers: [...], typeDefs: [...], plugins: [ new TransactionPlugin(pluginOptions), ] });
- Use database in resolver
import { getRunnerFromContext } from '@ams-pro/apollo-plugin-transaction'; const manager = getRunnerFromContext(context);
- Configure | Option | Required | Default | Description | |----------|----------|---------|-------------| | connection | Yes | | The Typeorm Connection used for database queries | enableStuckControl| No | false | Automatically abort transaction which take longer than the transaction timeout |transactionTimeout|No|60000|The transaction timeout used for the stuck control
Contributing
Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License.