elasticgraph-graphql 0.19.2.2 → 0.19.3.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: b0966dcde797efc0d2e1f22901440b313e803a1db5cce33f79b515078901560c
4
- data.tar.gz: 8508a1aafcbf466c4664dc95aaf2a112193df1a3f2edc92c40427ed8f96cd5a0
3
+ metadata.gz: 22324b1b8acd027bd6836c86194e398e8684cdaf85df7e98cd213482b451146f
4
+ data.tar.gz: 82b689cf8dda30d2988dc0a775123fb549929ca0b0fb3c3ff042da9b5dbf3944
5
5
  SHA512:
6
- metadata.gz: ccf09ea0494543be1b95d241d5592c1e35e4680b506c9776b1c823a83023af641c1ce4f71a305e8b733a72ef39d229f797aa8f1e21bfc2921a34cfb95d3c265b
7
- data.tar.gz: c4df4204da85ff79eda7ecfefde640a6f9344c52426148074e95cbc9330328f8e526cb874d9aa3e869797953b4fe04fb31c7fe276119de767ead86068375ad53
6
+ metadata.gz: fecaef223e61e420e4111391e236e6f8e7f2aceb26039fa8bd070704c5f2dec52321b3877c85a6aefa24ad87cca286780dbf8dc033615410885cff7b229a18ef
7
+ data.tar.gz: f5bdbe3017ad833d6c5cc7e847812a3af051179c2becdc11f39755f98c5f0eadca9dc0d5ce86ad6a711c3fecfa50c2b745be70c2e914350ec6b8ed82a8ee2284
@@ -29,8 +29,8 @@ module ElasticGraph
29
29
  class DatastoreQuery < Support::MemoizableData.define(
30
30
  :total_document_count_needed, :aggregations, :logger, :filter_interpreter, :routing_picker,
31
31
  :index_expression_builder, :default_page_size, :search_index_definitions, :max_page_size,
32
- :filters, :sort, :document_pagination, :requested_fields, :individual_docs_needed,
33
- :size_multiplier, :monotonic_clock_deadline, :schema_element_names
32
+ :filters, :sort, :document_pagination, :requested_fields, :request_all_fields,
33
+ :individual_docs_needed, :size_multiplier, :monotonic_clock_deadline, :schema_element_names
34
34
  )
35
35
  # Load these files after the `Query` class has been defined, to avoid
36
36
  # `TypeError: superclass mismatch for class Query`
@@ -99,17 +99,19 @@ module ElasticGraph
99
99
  filters: [],
100
100
  sort: [],
101
101
  requested_fields: [],
102
+ request_all_fields: false,
102
103
  document_pagination: {},
103
104
  size_multiplier: 1,
104
105
  monotonic_clock_deadline: nil,
105
106
  aggregations: {}
106
107
  )
107
108
  with(
108
- individual_docs_needed: self.individual_docs_needed || individual_docs_needed || !requested_fields.empty?,
109
+ individual_docs_needed: self.individual_docs_needed || individual_docs_needed || !requested_fields.empty? || request_all_fields,
109
110
  total_document_count_needed: self.total_document_count_needed || total_document_count_needed || aggregations.values.any?(&:needs_total_doc_count?),
110
111
  filters: self.filters + filters,
111
112
  sort: merge_attribute(:sort, sort),
112
113
  requested_fields: self.requested_fields + requested_fields,
114
+ request_all_fields: self.request_all_fields || request_all_fields,
113
115
  document_pagination: merge_attribute(:document_pagination, document_pagination),
114
116
  size_multiplier: self.size_multiplier * size_multiplier,
115
117
  monotonic_clock_deadline: [self.monotonic_clock_deadline, monotonic_clock_deadline].compact.min,
@@ -304,6 +306,7 @@ module ElasticGraph
304
306
  # at all--which means the datastore can avoid decompressing the _source field. Otherwise,
305
307
  # we only ask for the fields we need to return.
306
308
  def source
309
+ return true if request_all_fields
307
310
  requested_source_fields = requested_fields - ["id"]
308
311
  return false if requested_source_fields.empty?
309
312
  # Merging in requested_fields as _source:{includes:} based on Elasticsearch documentation:
@@ -336,6 +339,7 @@ module ElasticGraph
336
339
  size_multiplier: 1,
337
340
  aggregations: {},
338
341
  requested_fields: [],
342
+ request_all_fields: false,
339
343
  individual_docs_needed: false,
340
344
  total_document_count_needed: false,
341
345
  monotonic_clock_deadline: nil
@@ -356,7 +360,8 @@ module ElasticGraph
356
360
  size_multiplier: size_multiplier,
357
361
  aggregations: aggregations,
358
362
  requested_fields: requested_fields.to_set,
359
- individual_docs_needed: individual_docs_needed || !requested_fields.empty?,
363
+ request_all_fields: request_all_fields,
364
+ individual_docs_needed: individual_docs_needed || !requested_fields.empty? || request_all_fields,
360
365
  total_document_count_needed: total_document_count_needed || aggregations.values.any?(&:needs_total_doc_count?),
361
366
  monotonic_clock_deadline: monotonic_clock_deadline,
362
367
  filter_interpreter: filter_interpreter,
@@ -41,15 +41,22 @@ module ElasticGraph
41
41
  end
42
42
 
43
43
  def query_attributes_for(field:, lookahead:)
44
+ index_field_paths =
45
+ field.type
46
+ .unwrap_fully
47
+ .search_index_definitions
48
+ .flat_map { |index_def| index_def.fields_by_path.keys }
49
+ .to_set
50
+
44
51
  attributes =
45
52
  if field.type.relay_connection?
46
53
  {
47
54
  individual_docs_needed: pagination_fields_need_individual_docs?(lookahead),
48
- requested_fields: requested_fields_under(relay_connection_node_from(lookahead))
55
+ requested_fields: requested_fields_under(relay_connection_node_from(lookahead), index_field_paths)
49
56
  }
50
57
  else
51
58
  {
52
- requested_fields: requested_fields_under(lookahead)
59
+ requested_fields: requested_fields_under(lookahead, index_field_paths)
53
60
  }
54
61
  end
55
62
 
@@ -68,9 +75,9 @@ module ElasticGraph
68
75
  # can ignore its foreign key; but when we are determining requested fields for a parent type,
69
76
  # we need to identify the foreign key to request from the datastore, without recursing into
70
77
  # its children.
71
- def requested_fields_under(node, path_prefix: "")
78
+ def requested_fields_under(node, index_field_paths, path_prefix: "")
72
79
  fields = node.selections.flat_map do |child|
73
- requested_fields_for(child, path_prefix: path_prefix)
80
+ requested_fields_for(child, index_field_paths, path_prefix: path_prefix)
74
81
  end
75
82
 
76
83
  fields << "#{path_prefix}__typename" if field_for(node.field)&.type&.abstract?
@@ -79,14 +86,22 @@ module ElasticGraph
79
86
 
80
87
  # Identifies the fields we need to fetch from the datastore for the given node,
81
88
  # and recursing into the fields under it as needed.
82
- def requested_fields_for(node, path_prefix:)
89
+ def requested_fields_for(node, index_field_paths, path_prefix:)
83
90
  return [] if graphql_dynamic_field?(node)
84
91
 
85
92
  # @type var field: Schema::Field
86
93
  field = _ = field_for(node.field)
87
94
 
88
95
  if field.type.embedded_object?
89
- requested_fields_under(node, path_prefix: "#{path_prefix}#{field.name_in_index}.")
96
+ field_path = "#{path_prefix}#{field.name_in_index}"
97
+ if index_field_paths.include?(field_path)
98
+ # If we've reached a path to a scalar field, we should just return it instead of recursing.
99
+ # This allows an object field to use a `name_in_index` of a scalar field which can be
100
+ # necessary for some custom resolvers.
101
+ [field_path]
102
+ else
103
+ requested_fields_under(node, index_field_paths, path_prefix: "#{field_path}.")
104
+ end
90
105
  else
91
106
  field.index_field_names_for_resolution.map do |name|
92
107
  "#{path_prefix}#{name}"
@@ -17,7 +17,11 @@ module ElasticGraph
17
17
  class GraphQLAdapterBuilder
18
18
  def initialize(runtime_metadata:, named_resolvers:, query_adapter:)
19
19
  @runtime_metadata = runtime_metadata
20
- @named_resolvers = named_resolvers
20
+ @resolvers_by_name_and_field_config = named_resolvers.transform_values do |resolver_constructor|
21
+ ::Hash.new do |hash, field_config|
22
+ hash[field_config] = resolver_constructor.call(field_config)
23
+ end
24
+ end
21
25
  @query_adapter = query_adapter
22
26
  end
23
27
 
@@ -42,10 +46,10 @@ module ElasticGraph
42
46
  def object_type_hash
43
47
  @runtime_metadata.object_types_by_name.filter_map do |type_name, type|
44
48
  fields_hash = type.graphql_fields_by_name.filter_map do |field_name, field|
45
- if (resolver_name = field.resolver)
46
- resolver = @named_resolvers.fetch(resolver_name) do
47
- raise Errors::SchemaError, "Resolver `#{resolver_name}` (for `#{type_name}.#{field_name}`) cannot be found."
48
- end
49
+ if (configured_resolver = field.resolver)
50
+ resolver = @resolvers_by_name_and_field_config.fetch(configured_resolver.name) do
51
+ raise Errors::SchemaError, "Resolver `#{configured_resolver.name}` (for `#{type_name}.#{field_name}`) cannot be found."
52
+ end[configured_resolver.config]
49
53
 
50
54
  resolver_lambda =
51
55
  if resolver.method(:resolve).parameters.include?([:keyreq, :lookahead])
@@ -15,9 +15,9 @@ module ElasticGraph
15
15
  module RelayConnection
16
16
  # Relay connection adapter for an array. Implemented primarily by `GraphQL::Relay::ArrayConnection`;
17
17
  # here we just adapt it to the ElasticGraph internal resolver interface.
18
- class ArrayAdapter < ResolvableValue.new(:graphql_impl)
18
+ class ArrayAdapter < ResolvableValue.new(:graphql_impl, :total_edge_count)
19
19
  # `ResolvableValue.new` provides the following methods:
20
- # @dynamic initialize, graphql_impl, schema_element_names
20
+ # @dynamic initialize, graphql_impl, total_edge_count, schema_element_names
21
21
 
22
22
  # `def_delegators` provides the following methods:
23
23
  # @dynamic start_cursor, end_cursor, has_next_page, has_previous_page
@@ -25,20 +25,22 @@ module ElasticGraph
25
25
  def_delegators :graphql_impl, :start_cursor, :end_cursor, :has_next_page, :has_previous_page
26
26
 
27
27
  def self.build(nodes, args, schema_element_names, context)
28
+ nodes ||= [] # : ::Array[untyped]
28
29
  # ElasticGraph supports any schema elements (like a `first` argument) being renamed,
29
30
  # but `GraphQL::Relay::ArrayConnection` would not understand a renamed argument.
30
31
  # Here we map the args back to the canonical relay args so `ArrayConnection` can
31
32
  # understand them.
32
- relay_args = [:first, :after, :last, :before].to_h do |arg_name|
33
- [arg_name, args[schema_element_names.public_send(arg_name)]]
34
- end.compact
33
+ #
34
+ # `after` and `before` are encoded to convert them to the string form required by `ArrayConnection`.
35
+ relay_args = {
36
+ first: args[schema_element_names.first],
37
+ after: args[schema_element_names.after]&.encode,
38
+ last: args[schema_element_names.last],
39
+ before: args[schema_element_names.before]&.encode
40
+ }.compact
35
41
 
36
- graphql_impl = ::GraphQL::Pagination::ArrayConnection.new(nodes || [], context: context, **relay_args)
37
- new(schema_element_names, graphql_impl)
38
- end
39
-
40
- def total_edge_count
41
- graphql_impl.nodes.size
42
+ graphql_impl = ::GraphQL::Pagination::ArrayConnection.new(nodes, context: context, **relay_args)
43
+ new(schema_element_names, graphql_impl, nodes.size)
42
44
  end
43
45
 
44
46
  def page_info
@@ -29,7 +29,7 @@ module ElasticGraph
29
29
  @computation_detail = runtime_metadata&.computation_detail
30
30
  @resolver = runtime_metadata&.resolver
31
31
  @name_in_index = runtime_metadata&.name_in_index || name
32
- @graphql_field.extras([:lookahead]) if resolvers_needing_lookahead.include?(@resolver)
32
+ @graphql_field.extras([:lookahead]) if resolvers_needing_lookahead.include?(@resolver&.name)
33
33
  end
34
34
 
35
35
  def type
@@ -183,7 +183,13 @@ module ElasticGraph
183
183
  def named_graphql_resolvers
184
184
  @named_graphql_resolvers ||= runtime_metadata.graphql_resolvers_by_name.transform_values do |resolver|
185
185
  ext = resolver.load_resolver
186
- (_ = ext.extension_class).new(elasticgraph_graphql: self, config: ext.config)
186
+
187
+ ->(field_config) do
188
+ (_ = ext.extension_class).new(
189
+ elasticgraph_graphql: self,
190
+ config: ext.config.merge(field_config)
191
+ )
192
+ end
187
193
  end
188
194
  end
189
195
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticgraph-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.2.2
4
+ version: 0.19.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
@@ -9,7 +9,7 @@ authors:
9
9
  - Block Engineering
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-05-05 00:00:00.000000000 Z
12
+ date: 2025-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: base64
@@ -31,28 +31,28 @@ dependencies:
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 0.19.2.2
34
+ version: 0.19.3.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: 0.19.2.2
41
+ version: 0.19.3.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: elasticgraph-schema_artifacts
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - '='
47
47
  - !ruby/object:Gem::Version
48
- version: 0.19.2.2
48
+ version: 0.19.3.0
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: 0.19.2.2
55
+ version: 0.19.3.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: graphql
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -93,70 +93,70 @@ dependencies:
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.19.2.2
96
+ version: 0.19.3.0
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.19.2.2
103
+ version: 0.19.3.0
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: elasticgraph-elasticsearch
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.19.2.2
110
+ version: 0.19.3.0
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.19.2.2
117
+ version: 0.19.3.0
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: elasticgraph-opensearch
120
120
  requirement: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.19.2.2
124
+ version: 0.19.3.0
125
125
  type: :development
126
126
  prerelease: false
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.19.2.2
131
+ version: 0.19.3.0
132
132
  - !ruby/object:Gem::Dependency
133
133
  name: elasticgraph-indexer
134
134
  requirement: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.19.2.2
138
+ version: 0.19.3.0
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 0.19.2.2
145
+ version: 0.19.3.0
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: elasticgraph-schema_definition
148
148
  requirement: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 0.19.2.2
152
+ version: 0.19.3.0
153
153
  type: :development
154
154
  prerelease: false
155
155
  version_requirements: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 0.19.2.2
159
+ version: 0.19.3.0
160
160
  email:
161
161
  - myron@squareup.com
162
162
  executables: []
@@ -247,10 +247,10 @@ licenses:
247
247
  - MIT
248
248
  metadata:
249
249
  bug_tracker_uri: https://github.com/block/elasticgraph/issues
250
- changelog_uri: https://github.com/block/elasticgraph/releases/tag/v0.19.2.2
251
- documentation_uri: https://block.github.io/elasticgraph/api-docs/v0.19.2.2/
250
+ changelog_uri: https://github.com/block/elasticgraph/releases/tag/v0.19.3.0
251
+ documentation_uri: https://block.github.io/elasticgraph/api-docs/v0.19.3.0/
252
252
  homepage_uri: https://block.github.io/elasticgraph/
253
- source_code_uri: https://github.com/block/elasticgraph/tree/v0.19.2.2/elasticgraph-graphql
253
+ source_code_uri: https://github.com/block/elasticgraph/tree/v0.19.3.0/elasticgraph-graphql
254
254
  gem_category: core
255
255
  rdoc_options: []
256
256
  require_paths: