Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soundtrackyourbrand/absinthe-throttle
A pluggable throttling middleware for concurrent Absinthe queries
https://github.com/soundtrackyourbrand/absinthe-throttle
absinthe elixir web
Last synced: about 2 months ago
JSON representation
A pluggable throttling middleware for concurrent Absinthe queries
- Host: GitHub
- URL: https://github.com/soundtrackyourbrand/absinthe-throttle
- Owner: soundtrackyourbrand
- License: mit
- Created: 2017-08-29T11:54:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-07T13:51:30.000Z (about 7 years ago)
- Last Synced: 2024-11-19T19:15:08.362Z (2 months ago)
- Topics: absinthe, elixir, web
- Language: Elixir
- Size: 13.7 KB
- Stars: 13
- Watchers: 10
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AbsintheThrottle
[![Build Status](https://travis-ci.org/soundtrackyourbrand/absinthe-throttle.svg?branch=master)](https://travis-ci.org/soundtrackyourbrand/absinthe-throttle)
An [Absinthe](https://github.com/absinthe-graphql/absinthe) pipeline phase to throttle the number of queries that are resolved simultaneously.
```elixir
defmodule MyApp.Throttler do
use AbsintheThrottle,
adapter: AbsintheThrottle.Adapter.Semaphore,
arguments: [name: :resolve,
size: 1,
error: {:error, message: :custom_error, code: 123}]
enddefmodule MyApp.Router do
# ...
plug Absinthe.Plug,
schema: MyApp.Schema,
pipeline: {MyApp.Throttler.Plug, :pipeline}
# ...
end# or
"""
{
document {
id
}
}
"""
|> Absinthe.Pipeline.run(MyApp.Throttler.pipeline(MyApp.Schema))```
### Custom throttlers
You can implement a custom throttler using any throttling mechanism by implementing the `transaction/2` callback, see: [AbsintheThrottle.Adapter.Semaphore](https://github.com/soundtrackyourbrand/absinthe-throttle/blob/master/lib/adapter/semaphore.ex).
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `absinthe_throttle` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:absinthe_throttle, "~> 0.4.0"}
]
end
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/absinthe_throttle](https://hexdocs.pm/absinthe_throttle).