0.0.1 • Published 2 years ago

@ams-pro/apollo-plugin-dyco v0.0.1

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

Issues MIT License

About The Project

The plugin calculates a complexity based on the resolver runtime. The plugin measures the time it takes for a resolver to finish its execution. New requests estimate the runtime based on past executions and prevents the execution if the max complexity is exceeded. If there is no information for the request is available yet, the plugin tries to estimate based on the schema.

Getting started

Installation

npm install @ams-pro/apollo-plugin-dyco graphql

or

yarn add @ams-pro/apollo-plugin-dyco graphql

Usage

  1. Initialize the Plugin

    import { ComplexityExtension, ComplexityPlugin, MetricStore } from '@ams-pro/apollo-plugin-dyco';
    
    const metricStore = new MetricStore();
    
    const server = new ApolloServer({
        resolvers: [...],
        typeDefs: [...],
        plugins: [
          new ComplexityPlugin(options),
        ],
        extensions: [
          () => new ComplexityExtension(metricStore)
        ],
    });
  2. Configure the plugin | Option | Required | Default | Description | |----------|----------|---------|-------------| |store|Yes||The shared store used by the extension| |max|No|10000|The maximum allowed complexity| |logging|No|false|Enable logging of calculated complexity| |listMultiplier|No|5|Multiplier for estimating lists if no information is available yet |objectMultiplier|No|1.1|Multiplier for estimating objects if no information is available yet

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.