elasticgraph-query_registry 1.0.1 → 1.0.3.rc1
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 +4 -4
- data/LICENSE.txt +1 -1
- data/lib/elastic_graph/query_registry/client_data.rb +10 -4
- data/lib/elastic_graph/query_registry/config.rb +1 -1
- data/lib/elastic_graph/query_registry/graphql_extension.rb +4 -2
- data/lib/elastic_graph/query_registry/query_validator.rb +2 -2
- data/lib/elastic_graph/query_registry/query_validators/for_registered_client.rb +22 -6
- data/lib/elastic_graph/query_registry/query_validators/for_unregistered_client.rb +6 -4
- data/lib/elastic_graph/query_registry/rake_tasks.rb +2 -2
- data/lib/elastic_graph/query_registry/registration_status.rb +26 -0
- data/lib/elastic_graph/query_registry/registry.rb +1 -1
- data/lib/elastic_graph/query_registry/variable_backward_incompatibility_detector.rb +1 -1
- data/lib/elastic_graph/query_registry/variable_dumper.rb +1 -1
- metadata +23 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb564abc1761f7f942cc64e061058c3ed867345435fd18033f8a19cdd5552325
|
|
4
|
+
data.tar.gz: 9eb08a0c9151aae6cd7f03ecb27c8e634b0d280464205a3cdcdf911e57c55ce8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5d5205bb29eee0a3960d3ae6d26815241209f881ef7a581b23b70f0ad6c6c0db1fc00092f7464b969dc17bbe96fd4334a9b40f6dfde7509a32518a088c085d2
|
|
7
|
+
data.tar.gz: 0f2eb71c1237b17fd57e09a8e5f5f081179665c468e4236127ceba23bb2eaf62cab28ea7a0046eb62d480b3aede99d1bbabb738a1d57fd6064e486b1bee72321
|
data/LICENSE.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright 2024 -
|
|
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
|
-
|
|
58
|
-
|
|
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 `#{
|
|
68
|
+
"registered query with a `#{selected_op_name}` operation."
|
|
63
69
|
end
|
|
64
70
|
end
|
|
65
71
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright 2024 -
|
|
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 -
|
|
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 -
|
|
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
|
-
|
|
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 -
|
|
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 -
|
|
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
|
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.
|
|
4
|
+
version: 1.0.3.rc1
|
|
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.
|
|
20
|
+
version: 1.0.3.rc1
|
|
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.
|
|
27
|
+
version: 1.0.3.rc1
|
|
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.
|
|
34
|
+
version: 1.0.3.rc1
|
|
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.
|
|
41
|
+
version: 1.0.3.rc1
|
|
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.
|
|
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.
|
|
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.
|
|
102
|
+
version: 1.0.3.rc1
|
|
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.
|
|
109
|
+
version: 1.0.3.rc1
|
|
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.
|
|
116
|
+
version: 1.0.3.rc1
|
|
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.
|
|
123
|
+
version: 1.0.3.rc1
|
|
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.
|
|
142
|
-
documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.0.
|
|
148
|
+
changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.0.3.rc1
|
|
149
|
+
documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.0.3.rc1/
|
|
143
150
|
homepage_uri: https://block.github.io/elasticgraph/
|
|
144
|
-
source_code_uri: https://github.com/block/elasticgraph/tree/v1.0.
|
|
151
|
+
source_code_uri: https://github.com/block/elasticgraph/tree/v1.0.3.rc1/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: '
|
|
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:
|
|
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: []
|