Skip to content

Commit

Permalink
Migrate CompiledQueries instrumentation to tracer (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryTsepelev authored Jun 29, 2024
1 parent dea193d commit 086fce0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## master

- [PR#78](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/78)
Migrate CompiledQueries instrumentation to tracer ([@DmitryTsepelev][])

## 1.8.1 (2024-06-01)

- [PR#77](https://github.com/DmitryTsepelev/graphql-ruby-persisted_queries/pull/77)
Expand Down
16 changes: 16 additions & 0 deletions lib/graphql/persisted_queries/compiled_queries/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ def before_query(query)

def after_query(*); end
end

# Instrumentations were deprecated in 2.2.5, this is a module to migrate to new interface
module Tracer
def execute_query(query:)
GraphQL::PersistedQueries::CompiledQueries::Instrumentation.before_query(query)
super
end

def execute_multiplex(multiplex:)
multiplex.queries.each do |query|
GraphQL::PersistedQueries::CompiledQueries::Instrumentation.before_query(query)
end

super
end
end
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/graphql/persisted_queries/schema_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def patch(schema, compiled_queries)

def configure_compiled_queries(schema)
if graphql_ruby_after_2_2_5?
schema.trace_with(GraphQL::Tracing::LegacyHooksTrace)
schema.instance_exec { own_instrumenters[:query] << CompiledQueries::Instrumentation }
schema.trace_with(GraphQL::PersistedQueries::CompiledQueries::Instrumentation::Tracer)
else
schema.instrument :query, CompiledQueries::Instrumentation
end
Expand Down

0 comments on commit 086fce0

Please sign in to comment.