@ams-pro/apollo-plugin-transaction

A Plugin for automatic creation of a typeorm transaction per request

Usage no npm install needed!

<script type="module">
  import amsProApolloPluginTransaction from 'https://cdn.skypack.dev/@ams-pro/apollo-plugin-transaction';
</script>

README

Issues MIT License


Apollo Transaction Plugin

A plugin for wrapping GraphQL requests into typeorm transactions

Report Bug ยท Request Feature

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.