Skip to content

Instantly share code, notes, and snippets.

@karmajunkie
Created May 1, 2017 21:37
Show Gist options
  • Save karmajunkie/1bff516ca518e00f8be8144b1dccbcc4 to your computer and use it in GitHub Desktop.
Save karmajunkie/1bff516ca518e00f8be8144b1dccbcc4 to your computer and use it in GitHub Desktop.
defmodule Bling.GraphQL.Schema do
use Absinthe.Schema
def middleware([]=middleware, _field, _object), do: middleware
def middleware(middleware, field, object) do
Bling.GraphQL.ScoutMiddleware.instrument(middleware, field, object)
end
query do
#...
end
end
defmodule Bling.GraphQL.ScoutMiddleware do
@behaviour Absinthe.Middleware
@behaviour Absinthe.Plugin
def call( res, {:start, object_identifier, field_identifier }) do
IO.puts "Scout middleware"
ScoutApm.TrackedRequest.start_layer("Controller", "#{object_identifier}/#{field_identifier}" )
res
end
# def after_resolution(acc=%{__MODULE__: [layer_on | layers_after]}) do
def call( res, {:end, object_identifier, field_identifier }) do
ScoutApm.TrackedRequest.stop_layer fn
layer -> layer
end
res
end
def instrument(middleware, field, object) do
[{{ __MODULE__,:call}, {:start, object.identifier, field.identifier} } | middleware ] ++ [{{__MODULE__, :call}, {:end, object.identifier, field.identifier}}]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment