Class: GraphQL::Analyzer::Instrumentation::ElasticSearch
- Inherits:
-
Object
- Object
- GraphQL::Analyzer::Instrumentation::ElasticSearch
- Defined in:
- lib/graphql/analyzer/instrumentation/elastic_search.rb
Instance Method Summary collapse
-
#initialize ⇒ ElasticSearch
constructor
A new instance of ElasticSearch.
- #instrument(type, field) ⇒ Object
Constructor Details
#initialize ⇒ ElasticSearch
Returns a new instance of ElasticSearch.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/graphql/analyzer/instrumentation/elastic_search.rb', line 5 def initialize @notifications = [] ActiveSupport::Notifications.subscribe('search.elasticsearch') do |name, start, finish, id, payload| @notifications << { name: name, start: start, finish: finish, id: id, payload: payload } end end |
Instance Method Details
#instrument(type, field) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/graphql/analyzer/instrumentation/elastic_search.rb', line 18 def instrument(type, field) ->(obj, args, ctx) do result = field.resolve_proc.call(obj, args, ctx) if @notifications.any? # TODO: Merge results when a field makes two types of queries # e.g. path: ['user', 'name'] makes a SQL and ES Query. ctx['graphql-analyzer']['resolvers'] << { 'path' => ctx.path, 'adapter' => 'elasticsearch', 'parentType' => type.name, 'fieldName' => field.name, 'returnType' => field.type.to_s, 'details' => @notifications } @notifications = [] end result end end |