elasticgraph-query_registry 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bad9581bf6e6d3c25823d72cd6b716040ddb7f35245c456a1c060f1abb9c947d
4
- data.tar.gz: 396a7da0a2ab59a99e3a9da96fd4affdb2cf49090d2e719e7c24a902481fd801
3
+ metadata.gz: b33134934c160d200ddf228b73aeba0e88debbcd80cf0c9511daabbc21ec620d
4
+ data.tar.gz: 9eb08a0c9151aae6cd7f03ecb27c8e634b0d280464205a3cdcdf911e57c55ce8
5
5
  SHA512:
6
- metadata.gz: 2333ead2022db5833af27b97733d84e2b503dbc3cbeaf056f36461e54b32afaf507bdba66e67628c3fc5e89c4e5507a7d2f2c25138e71694a0867b92db365852
7
- data.tar.gz: acd27bbb6d6b52e4285cf7fb2aeedf55d4a37237a91d108cb30952f39ad5490f0bce62d93115d2c8652e4b8e17f1255c86fbd2f5663a60d2e86c975d9e721c8d
6
+ metadata.gz: a2c231c5261def56818080074082e1577cba8f7864188358a3ed237ec3e5b39e9cc4e247a5fbd35047fea82e57af9e7fdf7cd471d935a273e4a619f1b93b4cae
7
+ data.tar.gz: 0f2eb71c1237b17fd57e09a8e5f5f081179665c468e4236127ceba23bb2eaf62cab28ea7a0046eb62d480b3aede99d1bbabb738a1d57fd6064e486b1bee72321
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 - 2025 Block, Inc.
3
+ Copyright (c) 2024 - 2026 Block, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -54,12 +54,18 @@ module ElasticGraph
54
54
  end
55
55
 
56
56
  def unregistered_query_error_for(query, client)
57
- if operation_names.include?(query.operation_name.to_s)
58
- "Query #{fingerprint_for(query)} differs from the registered form of `#{query.operation_name}` " \
57
+ # Note: we use `selected_operation_name` instead of `operation_name` because `operation_name` can return
58
+ # `nil` for single-operation queries when no explicit operation_name parameter is passed if accessed before
59
+ # the query AST is parsed, whereas `selected_operation_name` parses the query AST and returns the operation
60
+ # name from the query document in that case.
61
+ selected_op_name = query.selected_operation_name.to_s
62
+
63
+ if operation_names.include?(selected_op_name)
64
+ "Query #{fingerprint_for(query)} differs from the registered form of `#{selected_op_name}` " \
59
65
  "for client #{client.description}."
60
66
  else
61
67
  "Query #{fingerprint_for(query)} is unregistered; client #{client.description} has no " \
62
- "registered query with a `#{query.operation_name}` operation."
68
+ "registered query with a `#{selected_op_name}` operation."
63
69
  end
64
70
  end
65
71
 
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -60,7 +60,7 @@ module ElasticGraph
60
60
  private
61
61
 
62
62
  def build_and_execute_query(query_string:, variables:, operation_name:, context:, client:)
63
- query, errors = @registry.build_and_validate_query(
63
+ query, errors, registration_status = @registry.build_and_validate_query(
64
64
  query_string,
65
65
  variables: variables,
66
66
  operation_name: operation_name,
@@ -68,6 +68,8 @@ module ElasticGraph
68
68
  client: client
69
69
  )
70
70
 
71
+ context.fetch(:elastic_graph_query_tracker)["query_registration_status"] = registration_status
72
+
71
73
  if errors.empty?
72
74
  [query, execute_query(query, client: client)]
73
75
  else
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -55,7 +55,7 @@ module ElasticGraph
55
55
  private
56
56
 
57
57
  def variables_errors_for(operation_name, old_dumped_variables, new_dumped_variables, client_name, query_name)
58
- rake_task = "rake \"query_registry:dump_variables[#{client_name}, #{query_name}]\""
58
+ rake_task = "bundle exec rake \"query_registry:dump_variables[#{client_name}, #{query_name}]\""
59
59
 
60
60
  if old_dumped_variables.nil? || old_dumped_variables[operation_name].nil?
61
61
  return [{"message" => "No dumped variables for this operation exist. Correct by running: `#{rake_task}`"}]
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -8,6 +8,7 @@
8
8
 
9
9
  require "elastic_graph/graphql/client"
10
10
  require "elastic_graph/query_registry/client_data"
11
+ require "elastic_graph/query_registry/registration_status"
11
12
  require "graphql"
12
13
 
13
14
  module ElasticGraph
@@ -44,19 +45,34 @@ module ElasticGraph
44
45
 
45
46
  if (cached_query = client_data.cached_query_for(query_string.to_s))
46
47
  prepared_query = prepare_query_for_execution(cached_query, variables: variables, operation_name: operation_name, context: context)
47
- return [prepared_query, []]
48
+ return [prepared_query, [], RegistrationStatus::MATCHED_REGISTERED_QUERY]
48
49
  end
49
50
 
50
51
  query = yield
51
52
 
53
+ # Check operation name first (fast O(1) set lookup) to avoid canonicalization when not needed.
54
+ # Note: we use `selected_operation_name` instead of `operation_name` because `operation_name` returns
55
+ # `nil` for single-operation queries when no explicit operation_name parameter is passed, whereas
56
+ # `selected_operation_name` returns the operation name from the query document in that case.
57
+ registration_status =
58
+ if client_data.operation_names.include?(query.selected_operation_name.to_s)
59
+ if client_data.canonical_query_strings.include?(ClientData.canonical_query_string_from(query, schema_element_names: schema.element_names))
60
+ RegistrationStatus::MATCHED_REGISTERED_QUERY
61
+ else
62
+ RegistrationStatus::DIFFERING_REGISTERED_QUERY
63
+ end
64
+ else
65
+ RegistrationStatus::UNREGISTERED_QUERY
66
+ end
67
+
52
68
  # This client allows any query, so we can just return the query with no errors here.
53
69
  # Note: we could put this at the top of the method, but if the query is registered and matches
54
70
  # the registered form, the `cached_query` above is more efficient as it avoids unnecessarily
55
71
  # parsing the query.
56
- return [query, []] if allow_any_query_for_clients.include?(client.name)
72
+ return [query, [], registration_status] if allow_any_query_for_clients.include?(client.name)
57
73
 
58
- if !client_data.canonical_query_strings.include?(ClientData.canonical_query_string_from(query, schema_element_names: schema.element_names))
59
- return [query, [client_data.unregistered_query_error_for(query, client)]]
74
+ unless registration_status == RegistrationStatus::MATCHED_REGISTERED_QUERY
75
+ return [query, [client_data.unregistered_query_error_for(query, client)], registration_status]
60
76
  end
61
77
 
62
78
  # The query is slightly different from a registered query, but not in any material fashion
@@ -74,7 +90,7 @@ module ElasticGraph
74
90
  (_ = cached_client_data).with_updated_last_query(query_string, cachable_query)
75
91
  end
76
92
 
77
- [query, []]
93
+ [query, [], registration_status]
78
94
  end
79
95
 
80
96
  private
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -6,6 +6,8 @@
6
6
  #
7
7
  # frozen_string_literal: true
8
8
 
9
+ require "elastic_graph/query_registry/registration_status"
10
+
9
11
  module ElasticGraph
10
12
  module QueryRegistry
11
13
  module QueryValidators
@@ -15,15 +17,15 @@ module ElasticGraph
15
17
  def build_and_validate_query(query_string, client:, variables: {}, operation_name: nil, context: {})
16
18
  query = yield
17
19
 
18
- return [query, []] if allow_unregistered_clients
20
+ return [query, [], RegistrationStatus::UNREGISTERED_CLIENT] if allow_unregistered_clients
19
21
 
20
22
  client_name = client&.name
21
- return [query, []] if client_name && allow_any_query_for_clients.include?(client_name)
23
+ return [query, [], RegistrationStatus::UNREGISTERED_CLIENT] if client_name && allow_any_query_for_clients.include?(client_name)
22
24
 
23
25
  [query, [
24
26
  "Client #{client&.description || "(unknown)"} is not a registered client, it is not in " \
25
27
  "`allow_any_query_for_clients` and `allow_unregistered_clients` is false."
26
- ]]
28
+ ], RegistrationStatus::UNREGISTERED_CLIENT]
27
29
  end
28
30
  end
29
31
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -76,7 +76,7 @@ module ElasticGraph
76
76
  query_name = file_name[%r{/[^/]+/([^/]+)\.variables\.yaml}, 1]
77
77
 
78
78
  <<~EOS
79
- # Generated by `rake "query_registry:dump_variables[#{client_name}, #{query_name}]"`.
79
+ # Generated by `bundle exec rake "query_registry:dump_variables[#{client_name}, #{query_name}]"`.
80
80
  # DO NOT EDIT BY HAND. Any edits will be lost the next time the rake task is run.
81
81
  #
82
82
  # This file exists to allow `elasticgraph-query_registry` to track the structure of
@@ -0,0 +1,26 @@
1
+ # Copyright 2024 - 2026 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ module ElasticGraph
10
+ module QueryRegistry
11
+ # Constants for query registration status values logged in `ElasticGraphQueryExecutorQueryDuration`.
12
+ module RegistrationStatus
13
+ # Query exactly matched a registered query (used from cache).
14
+ MATCHED_REGISTERED_QUERY = "matched_registered_query"
15
+
16
+ # Query has same operation name as a registered query but query body differs.
17
+ DIFFERING_REGISTERED_QUERY = "differing_registered_query"
18
+
19
+ # Client is registered but has no query with this operation name.
20
+ UNREGISTERED_QUERY = "unregistered_query"
21
+
22
+ # Client is not registered in the query registry.
23
+ UNREGISTERED_CLIENT = "unregistered_client"
24
+ end
25
+ end
26
+ end
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
@@ -1,4 +1,4 @@
1
- # Copyright 2024 - 2025 Block, Inc.
1
+ # Copyright 2024 - 2026 Block, Inc.
2
2
  #
3
3
  # Use of this source code is governed by an MIT-style
4
4
  # license that can be found in the LICENSE file or at
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticgraph-query_registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.2
20
+ version: 1.1.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.0.2
27
+ version: 1.1.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: elasticgraph-support
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 1.0.2
34
+ version: 1.1.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: 1.0.2
41
+ version: 1.1.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: graphql
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '='
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 2.5.11
48
+ version: 2.5.18
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '='
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 2.5.11
55
+ version: 2.5.18
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: graphql-c_parser
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,9 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '13.3'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 13.3.1
83
86
  type: :runtime
84
87
  prerelease: false
85
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -87,34 +90,37 @@ dependencies:
87
90
  - - "~>"
88
91
  - !ruby/object:Gem::Version
89
92
  version: '13.3'
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 13.3.1
90
96
  - !ruby/object:Gem::Dependency
91
97
  name: elasticgraph-elasticsearch
92
98
  requirement: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - '='
95
101
  - !ruby/object:Gem::Version
96
- version: 1.0.2
102
+ version: 1.1.0
97
103
  type: :development
98
104
  prerelease: false
99
105
  version_requirements: !ruby/object:Gem::Requirement
100
106
  requirements:
101
107
  - - '='
102
108
  - !ruby/object:Gem::Version
103
- version: 1.0.2
109
+ version: 1.1.0
104
110
  - !ruby/object:Gem::Dependency
105
111
  name: elasticgraph-opensearch
106
112
  requirement: !ruby/object:Gem::Requirement
107
113
  requirements:
108
114
  - - '='
109
115
  - !ruby/object:Gem::Version
110
- version: 1.0.2
116
+ version: 1.1.0
111
117
  type: :development
112
118
  prerelease: false
113
119
  version_requirements: !ruby/object:Gem::Requirement
114
120
  requirements:
115
121
  - - '='
116
122
  - !ruby/object:Gem::Version
117
- version: 1.0.2
123
+ version: 1.1.0
118
124
  email:
119
125
  - myron@squareup.com
120
126
  executables: []
@@ -130,6 +136,7 @@ files:
130
136
  - lib/elastic_graph/query_registry/query_validators/for_registered_client.rb
131
137
  - lib/elastic_graph/query_registry/query_validators/for_unregistered_client.rb
132
138
  - lib/elastic_graph/query_registry/rake_tasks.rb
139
+ - lib/elastic_graph/query_registry/registration_status.rb
133
140
  - lib/elastic_graph/query_registry/registry.rb
134
141
  - lib/elastic_graph/query_registry/variable_backward_incompatibility_detector.rb
135
142
  - lib/elastic_graph/query_registry/variable_dumper.rb
@@ -138,10 +145,10 @@ licenses:
138
145
  - MIT
139
146
  metadata:
140
147
  bug_tracker_uri: https://github.com/block/elasticgraph/issues
141
- changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.0.2
142
- documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.0.2/
148
+ changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.1.0
149
+ documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.1.0/
143
150
  homepage_uri: https://block.github.io/elasticgraph/
144
- source_code_uri: https://github.com/block/elasticgraph/tree/v1.0.2/elasticgraph-query_registry
151
+ source_code_uri: https://github.com/block/elasticgraph/tree/v1.1.0/elasticgraph-query_registry
145
152
  gem_category: extension
146
153
  rdoc_options: []
147
154
  require_paths:
@@ -153,14 +160,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
160
  version: '3.4'
154
161
  - - "<"
155
162
  - !ruby/object:Gem::Version
156
- version: '3.5'
163
+ version: '4.1'
157
164
  required_rubygems_version: !ruby/object:Gem::Requirement
158
165
  requirements:
159
166
  - - ">="
160
167
  - !ruby/object:Gem::Version
161
168
  version: '0'
162
169
  requirements: []
163
- rubygems_version: 3.6.9
170
+ rubygems_version: 4.0.3
164
171
  specification_version: 4
165
172
  summary: Provides a source-controlled query registry for ElasticGraph applications.
166
173
  test_files: []