Skip to content

A pluggable throttling middleware for concurrent Absinthe queries

License

Notifications You must be signed in to change notification settings

soundtrackyourbrand/absinthe-throttle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AbsintheThrottle

Build Status

An Absinthe pipeline phase to throttle the number of queries that are resolved simultaneously.

defmodule MyApp.Throttler do
  use AbsintheThrottle,
      adapter: AbsintheThrottle.Adapter.Semaphore,
      arguments: [name: :resolve,
                  size: 1,
                  error: {:error, message: :custom_error, code: 123}]
end


defmodule 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.

Installation

If available in Hex, the package can be installed by adding absinthe_throttle to your list of dependencies in mix.exs:

def deps do
  [
    {:absinthe_throttle, "~> 0.4.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/absinthe_throttle.

About

A pluggable throttling middleware for concurrent Absinthe queries

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages