0.0.2 • Published 4 years ago

@ams-pro/apollo-plugin-transaction v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Issues MIT License

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

  1. Initialize the Plugin

    import { TransactionPlugin } from '@ams-pro/apollo-plugin-transaction';
    
    // Setup database connection
    
    const server = new ApolloServer({
        resolvers: [...],
        typeDefs: [...],
        plugins: [
            new TransactionPlugin(pluginOptions),
        ]
    });
  2. Use database in resolver

    import { getRunnerFromContext } from '@ams-pro/apollo-plugin-transaction';
    
    const manager = getRunnerFromContext(context);
  3. 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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License.