Skip to content

Commit 04aa0e7

Browse files
authored
Merge pull request #986 from block/myron/use-selected-operation-name
Prefer `selected_operation_name` over `operation_name`.
2 parents df70238 + b30e088 commit 04aa0e7

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

elasticgraph-graphql/lib/elastic_graph/graphql/query_executor.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def execute(
6565

6666
unless result.to_h.fetch("errors", []).empty?
6767
@logger.error <<~EOS
68-
Query #{query.operation_name}[1] for client #{client.description} resulted in errors[2].
68+
Query #{query.selected_operation_name}[1] for client #{client.description} resulted in errors[2].
6969
7070
[1] #{full_description_of(query)}
7171
@@ -79,7 +79,7 @@ def execute(
7979
# returns `nil` on an invalid query, and I don't want to risk leaking PII by logging the raw query string, so
8080
# we don't log any form of the query in that case.
8181
if duration > @slow_query_threshold_ms
82-
@logger.warn "Query #{query.operation_name} for client #{client.description} with shard routing values " \
82+
@logger.warn "Query #{query.selected_operation_name} for client #{client.description} with shard routing values " \
8383
"#{query_tracker.shard_routing_values.sort.inspect} and search index expressions #{query_tracker.search_index_expressions.sort.inspect} took longer " \
8484
"(#{duration} ms) than the configured slow query threshold (#{@slow_query_threshold_ms} ms). " \
8585
"Sanitized query:\n\n#{query.sanitized_query_string}"
@@ -90,7 +90,7 @@ def execute(
9090
"message_type" => "ElasticGraphQueryExecutorQueryDuration",
9191
"client" => client.name,
9292
"query_fingerprint" => fingerprint_for(query),
93-
"query_name" => query.operation_name,
93+
"query_name" => query.selected_operation_name,
9494
"duration_ms" => duration,
9595
# How long the datastore queries took according to what the datastore itself reported.
9696
"datastore_server_duration_ms" => query_tracker.datastore_query_server_duration_ms,
@@ -147,7 +147,7 @@ def execute_query(query, client:)
147147
query.result
148148
rescue => ex
149149
@logger.error <<~EOS
150-
Query #{query.operation_name}[1] for client #{client.description} failed with an exception[2].
150+
Query #{query.selected_operation_name}[1] for client #{client.description} failed with an exception[2].
151151
152152
[1] #{full_description_of(query)}
153153

elasticgraph-graphql/sig/graphql_gem.rbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ module GraphQL
105105
) -> void
106106

107107
attr_reader document: Language::Nodes::Document
108-
attr_reader operation_name: ::String?
108+
109+
# Commented out to discourage use--`selected_operation_name` should be preferred since `operation_name`
110+
# may only be populated after the query AST is parsed.
111+
# attr_reader operation_name: ::String?
112+
109113
attr_reader operations: ::Hash[::String, Language::Nodes::OperationDefinition]
110114
attr_reader fingerprint: ::String
111115
attr_reader sanitized_query_string: ::String?

0 commit comments

Comments
 (0)