elasticgraph-graphql 0.19.1.1 → 0.19.2.1

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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/lib/elastic_graph/graphql/aggregation/composite_grouping_adapter.rb +1 -1
  4. data/lib/elastic_graph/graphql/aggregation/computation.rb +1 -1
  5. data/lib/elastic_graph/graphql/aggregation/date_histogram_grouping.rb +1 -1
  6. data/lib/elastic_graph/graphql/aggregation/field_path_encoder.rb +1 -1
  7. data/lib/elastic_graph/graphql/aggregation/field_term_grouping.rb +1 -1
  8. data/lib/elastic_graph/graphql/aggregation/key.rb +1 -1
  9. data/lib/elastic_graph/graphql/aggregation/nested_sub_aggregation.rb +1 -1
  10. data/lib/elastic_graph/graphql/aggregation/non_composite_grouping_adapter.rb +2 -2
  11. data/lib/elastic_graph/graphql/aggregation/path_segment.rb +2 -2
  12. data/lib/elastic_graph/graphql/aggregation/query.rb +1 -1
  13. data/lib/elastic_graph/graphql/aggregation/query_adapter.rb +33 -6
  14. data/lib/elastic_graph/graphql/aggregation/query_optimizer.rb +1 -1
  15. data/lib/elastic_graph/graphql/aggregation/resolvers/aggregated_values.rb +2 -6
  16. data/lib/elastic_graph/graphql/aggregation/resolvers/count_detail.rb +1 -1
  17. data/lib/elastic_graph/graphql/aggregation/resolvers/grouped_by.rb +26 -6
  18. data/lib/elastic_graph/graphql/aggregation/resolvers/node.rb +1 -1
  19. data/lib/elastic_graph/graphql/aggregation/resolvers/relay_connection_builder.rb +5 -6
  20. data/lib/elastic_graph/graphql/aggregation/resolvers/sub_aggregations.rb +10 -8
  21. data/lib/elastic_graph/graphql/aggregation/script_term_grouping.rb +1 -1
  22. data/lib/elastic_graph/graphql/aggregation/term_grouping.rb +2 -2
  23. data/lib/elastic_graph/graphql/client.rb +1 -1
  24. data/lib/elastic_graph/graphql/config.rb +21 -6
  25. data/lib/elastic_graph/graphql/datastore_query/document_paginator.rb +10 -5
  26. data/lib/elastic_graph/graphql/datastore_query/index_expression_builder.rb +2 -3
  27. data/lib/elastic_graph/graphql/datastore_query/paginator.rb +1 -1
  28. data/lib/elastic_graph/graphql/datastore_query/routing_picker.rb +2 -3
  29. data/lib/elastic_graph/graphql/datastore_query.rb +66 -74
  30. data/lib/elastic_graph/graphql/datastore_response/document.rb +1 -1
  31. data/lib/elastic_graph/graphql/datastore_response/search_response.rb +83 -9
  32. data/lib/elastic_graph/graphql/datastore_search_router.rb +19 -4
  33. data/lib/elastic_graph/graphql/decoded_cursor.rb +1 -1
  34. data/lib/elastic_graph/graphql/filtering/boolean_query.rb +1 -1
  35. data/lib/elastic_graph/graphql/filtering/field_path.rb +1 -1
  36. data/lib/elastic_graph/graphql/filtering/filter_args_translator.rb +2 -2
  37. data/lib/elastic_graph/graphql/filtering/filter_interpreter.rb +10 -5
  38. data/lib/elastic_graph/graphql/filtering/filter_node_interpreter.rb +2 -2
  39. data/lib/elastic_graph/graphql/filtering/filter_value_set_extractor.rb +17 -2
  40. data/lib/elastic_graph/graphql/filtering/range_query.rb +1 -1
  41. data/lib/elastic_graph/graphql/http_endpoint.rb +2 -2
  42. data/lib/elastic_graph/graphql/query_adapter/filters.rb +1 -1
  43. data/lib/elastic_graph/graphql/query_adapter/pagination.rb +1 -1
  44. data/lib/elastic_graph/graphql/query_adapter/requested_fields.rb +18 -3
  45. data/lib/elastic_graph/graphql/query_adapter/sort.rb +1 -1
  46. data/lib/elastic_graph/graphql/query_details_tracker.rb +11 -14
  47. data/lib/elastic_graph/graphql/query_executor.rb +10 -16
  48. data/lib/elastic_graph/graphql/resolvers/get_record_field_value.rb +6 -12
  49. data/lib/elastic_graph/graphql/resolvers/graphql_adapter_builder.rb +126 -0
  50. data/lib/elastic_graph/graphql/resolvers/list_records.rb +4 -4
  51. data/lib/elastic_graph/graphql/resolvers/nested_relationships.rb +57 -27
  52. data/lib/elastic_graph/graphql/resolvers/nested_relationships_source.rb +325 -0
  53. data/lib/elastic_graph/graphql/resolvers/object.rb +36 -0
  54. data/lib/elastic_graph/graphql/resolvers/query_adapter.rb +2 -2
  55. data/lib/elastic_graph/graphql/resolvers/query_source.rb +6 -3
  56. data/lib/elastic_graph/graphql/resolvers/relay_connection/array_adapter.rb +1 -1
  57. data/lib/elastic_graph/graphql/resolvers/relay_connection/generic_adapter.rb +1 -1
  58. data/lib/elastic_graph/graphql/resolvers/relay_connection/page_info.rb +1 -1
  59. data/lib/elastic_graph/graphql/resolvers/relay_connection/search_response_adapter_builder.rb +1 -1
  60. data/lib/elastic_graph/graphql/resolvers/relay_connection.rb +2 -2
  61. data/lib/elastic_graph/graphql/resolvers/resolvable_value.rb +2 -7
  62. data/lib/elastic_graph/graphql/scalar_coercion_adapters/cursor.rb +1 -1
  63. data/lib/elastic_graph/graphql/scalar_coercion_adapters/date.rb +1 -1
  64. data/lib/elastic_graph/graphql/scalar_coercion_adapters/date_time.rb +1 -1
  65. data/lib/elastic_graph/graphql/scalar_coercion_adapters/local_time.rb +1 -1
  66. data/lib/elastic_graph/graphql/scalar_coercion_adapters/longs.rb +1 -1
  67. data/lib/elastic_graph/graphql/scalar_coercion_adapters/no_op.rb +1 -1
  68. data/lib/elastic_graph/graphql/scalar_coercion_adapters/time_zone.rb +1 -1
  69. data/lib/elastic_graph/graphql/scalar_coercion_adapters/untyped.rb +1 -1
  70. data/lib/elastic_graph/graphql/scalar_coercion_adapters/valid_time_zones.rb +1 -1
  71. data/lib/elastic_graph/graphql/schema/arguments.rb +1 -1
  72. data/lib/elastic_graph/graphql/schema/enum_value.rb +1 -1
  73. data/lib/elastic_graph/graphql/schema/field.rb +12 -27
  74. data/lib/elastic_graph/graphql/schema/relation_join.rb +17 -9
  75. data/lib/elastic_graph/graphql/schema/type.rb +19 -8
  76. data/lib/elastic_graph/graphql/schema.rb +83 -29
  77. data/lib/elastic_graph/graphql.rb +56 -43
  78. data/script/dump_time_zones +1 -1
  79. metadata +59 -29
  80. data/lib/elastic_graph/graphql/monkey_patches/schema_field.rb +0 -56
  81. data/lib/elastic_graph/graphql/monkey_patches/schema_object.rb +0 -48
  82. data/lib/elastic_graph/graphql/resolvers/graphql_adapter.rb +0 -114
metadata CHANGED
@@ -1,130 +1,162 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticgraph-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1.1
4
+ version: 0.19.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
8
8
  - Ben VandenBos
9
9
  - Block Engineering
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2025-02-07 00:00:00.000000000 Z
12
+ date: 2025-04-24 00:00:00.000000000 Z
14
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: base64
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.2'
15
28
  - !ruby/object:Gem::Dependency
16
29
  name: elasticgraph-datastore_core
17
30
  requirement: !ruby/object:Gem::Requirement
18
31
  requirements:
19
32
  - - '='
20
33
  - !ruby/object:Gem::Version
21
- version: 0.19.1.1
34
+ version: 0.19.2.1
22
35
  type: :runtime
23
36
  prerelease: false
24
37
  version_requirements: !ruby/object:Gem::Requirement
25
38
  requirements:
26
39
  - - '='
27
40
  - !ruby/object:Gem::Version
28
- version: 0.19.1.1
41
+ version: 0.19.2.1
29
42
  - !ruby/object:Gem::Dependency
30
43
  name: elasticgraph-schema_artifacts
31
44
  requirement: !ruby/object:Gem::Requirement
32
45
  requirements:
33
46
  - - '='
34
47
  - !ruby/object:Gem::Version
35
- version: 0.19.1.1
48
+ version: 0.19.2.1
36
49
  type: :runtime
37
50
  prerelease: false
38
51
  version_requirements: !ruby/object:Gem::Requirement
39
52
  requirements:
40
53
  - - '='
41
54
  - !ruby/object:Gem::Version
42
- version: 0.19.1.1
55
+ version: 0.19.2.1
43
56
  - !ruby/object:Gem::Dependency
44
57
  name: graphql
45
58
  requirement: !ruby/object:Gem::Requirement
46
59
  requirements:
47
60
  - - "~>"
48
61
  - !ruby/object:Gem::Version
49
- version: 2.4.8
62
+ version: 2.5.4
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 2.5.4
70
+ - !ruby/object:Gem::Dependency
71
+ name: graphql-c_parser
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.1'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.1.2
50
80
  type: :runtime
51
81
  prerelease: false
52
82
  version_requirements: !ruby/object:Gem::Requirement
53
83
  requirements:
54
84
  - - "~>"
55
85
  - !ruby/object:Gem::Version
56
- version: 2.4.8
86
+ version: '1.1'
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.2
57
90
  - !ruby/object:Gem::Dependency
58
91
  name: elasticgraph-admin
59
92
  requirement: !ruby/object:Gem::Requirement
60
93
  requirements:
61
94
  - - '='
62
95
  - !ruby/object:Gem::Version
63
- version: 0.19.1.1
96
+ version: 0.19.2.1
64
97
  type: :development
65
98
  prerelease: false
66
99
  version_requirements: !ruby/object:Gem::Requirement
67
100
  requirements:
68
101
  - - '='
69
102
  - !ruby/object:Gem::Version
70
- version: 0.19.1.1
103
+ version: 0.19.2.1
71
104
  - !ruby/object:Gem::Dependency
72
105
  name: elasticgraph-elasticsearch
73
106
  requirement: !ruby/object:Gem::Requirement
74
107
  requirements:
75
108
  - - '='
76
109
  - !ruby/object:Gem::Version
77
- version: 0.19.1.1
110
+ version: 0.19.2.1
78
111
  type: :development
79
112
  prerelease: false
80
113
  version_requirements: !ruby/object:Gem::Requirement
81
114
  requirements:
82
115
  - - '='
83
116
  - !ruby/object:Gem::Version
84
- version: 0.19.1.1
117
+ version: 0.19.2.1
85
118
  - !ruby/object:Gem::Dependency
86
119
  name: elasticgraph-opensearch
87
120
  requirement: !ruby/object:Gem::Requirement
88
121
  requirements:
89
122
  - - '='
90
123
  - !ruby/object:Gem::Version
91
- version: 0.19.1.1
124
+ version: 0.19.2.1
92
125
  type: :development
93
126
  prerelease: false
94
127
  version_requirements: !ruby/object:Gem::Requirement
95
128
  requirements:
96
129
  - - '='
97
130
  - !ruby/object:Gem::Version
98
- version: 0.19.1.1
131
+ version: 0.19.2.1
99
132
  - !ruby/object:Gem::Dependency
100
133
  name: elasticgraph-indexer
101
134
  requirement: !ruby/object:Gem::Requirement
102
135
  requirements:
103
136
  - - '='
104
137
  - !ruby/object:Gem::Version
105
- version: 0.19.1.1
138
+ version: 0.19.2.1
106
139
  type: :development
107
140
  prerelease: false
108
141
  version_requirements: !ruby/object:Gem::Requirement
109
142
  requirements:
110
143
  - - '='
111
144
  - !ruby/object:Gem::Version
112
- version: 0.19.1.1
145
+ version: 0.19.2.1
113
146
  - !ruby/object:Gem::Dependency
114
147
  name: elasticgraph-schema_definition
115
148
  requirement: !ruby/object:Gem::Requirement
116
149
  requirements:
117
150
  - - '='
118
151
  - !ruby/object:Gem::Version
119
- version: 0.19.1.1
152
+ version: 0.19.2.1
120
153
  type: :development
121
154
  prerelease: false
122
155
  version_requirements: !ruby/object:Gem::Requirement
123
156
  requirements:
124
157
  - - '='
125
158
  - !ruby/object:Gem::Version
126
- version: 0.19.1.1
127
- description:
159
+ version: 0.19.2.1
128
160
  email:
129
161
  - myron@squareup.com
130
162
  executables: []
@@ -173,8 +205,6 @@ files:
173
205
  - lib/elastic_graph/graphql/filtering/filter_value_set_extractor.rb
174
206
  - lib/elastic_graph/graphql/filtering/range_query.rb
175
207
  - lib/elastic_graph/graphql/http_endpoint.rb
176
- - lib/elastic_graph/graphql/monkey_patches/schema_field.rb
177
- - lib/elastic_graph/graphql/monkey_patches/schema_object.rb
178
208
  - lib/elastic_graph/graphql/query_adapter/filters.rb
179
209
  - lib/elastic_graph/graphql/query_adapter/pagination.rb
180
210
  - lib/elastic_graph/graphql/query_adapter/requested_fields.rb
@@ -182,9 +212,11 @@ files:
182
212
  - lib/elastic_graph/graphql/query_details_tracker.rb
183
213
  - lib/elastic_graph/graphql/query_executor.rb
184
214
  - lib/elastic_graph/graphql/resolvers/get_record_field_value.rb
185
- - lib/elastic_graph/graphql/resolvers/graphql_adapter.rb
215
+ - lib/elastic_graph/graphql/resolvers/graphql_adapter_builder.rb
186
216
  - lib/elastic_graph/graphql/resolvers/list_records.rb
187
217
  - lib/elastic_graph/graphql/resolvers/nested_relationships.rb
218
+ - lib/elastic_graph/graphql/resolvers/nested_relationships_source.rb
219
+ - lib/elastic_graph/graphql/resolvers/object.rb
188
220
  - lib/elastic_graph/graphql/resolvers/query_adapter.rb
189
221
  - lib/elastic_graph/graphql/resolvers/query_source.rb
190
222
  - lib/elastic_graph/graphql/resolvers/relay_connection.rb
@@ -215,12 +247,11 @@ licenses:
215
247
  - MIT
216
248
  metadata:
217
249
  bug_tracker_uri: https://github.com/block/elasticgraph/issues
218
- changelog_uri: https://github.com/block/elasticgraph/releases/tag/v0.19.1.1
219
- documentation_uri: https://block.github.io/elasticgraph/docs/main/
250
+ changelog_uri: https://github.com/block/elasticgraph/releases/tag/v0.19.2.1
251
+ documentation_uri: https://block.github.io/elasticgraph/api-docs/v0.19.2.1/
220
252
  homepage_uri: https://block.github.io/elasticgraph/
221
- source_code_uri: https://github.com/block/elasticgraph/tree/v0.19.1.1/elasticgraph-graphql
253
+ source_code_uri: https://github.com/block/elasticgraph/tree/v0.19.2.1/elasticgraph-graphql
222
254
  gem_category: core
223
- post_install_message:
224
255
  rdoc_options: []
225
256
  require_paths:
226
257
  - lib
@@ -238,8 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
269
  - !ruby/object:Gem::Version
239
270
  version: '0'
240
271
  requirements: []
241
- rubygems_version: 3.5.22
242
- signing_key:
272
+ rubygems_version: 3.6.2
243
273
  specification_version: 4
244
274
  summary: The ElasticGraph GraphQL query engine.
245
275
  test_files: []
@@ -1,56 +0,0 @@
1
- # Copyright 2024 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
- require "graphql"
10
-
11
- module ElasticGraph
12
- class GraphQL
13
- module MonkeyPatches
14
- # This module is designed to monkey patch `GraphQL::Schema::Field`, but to do so in a
15
- # conservative, safe way:
16
- #
17
- # - It defines no new methods.
18
- # - It delegates to the original implementation with `super` unless we are sure that a type should be hidden.
19
- # - It only changes the behavior for ElasticGraph schemas (as indicated by `:elastic_graph_schema` in the `context`).
20
- module SchemaFieldVisibilityDecorator
21
- def visible?(context)
22
- # `DynamicFields` and `EntryPoints` are built-in introspection types that `field_named` below doesn't support:
23
- # https://github.com/rmosolgo/graphql-ruby/blob/0df187995c971b399ed7cc1fbdcbd958af6c4ade/lib/graphql/introspection/entry_points.rb
24
- # https://github.com/rmosolgo/graphql-ruby/blob/0df187995c971b399ed7cc1fbdcbd958af6c4ade/lib/graphql/introspection/dynamic_fields.rb
25
- #
26
- # ...so if the owner is one of those we just return `super` here.
27
- return super if %w[DynamicFields EntryPoints].include?(owner.graphql_name)
28
-
29
- if context[:elastic_graph_schema]&.field_named(owner.graphql_name, graphql_name)&.hidden_from_queries?
30
- return false
31
- end
32
-
33
- super
34
- end
35
- end
36
- end
37
- end
38
- end
39
-
40
- # As per https://graphql-ruby.org/authorization/visibility.html, the public API
41
- # provided by the GraphQL gem to control visibility of object types is to define
42
- # a `visible?` instance method on a custom subclass of `GraphQL::Schema::Field`.
43
- # However, because we load our schema from an SDL definition rather than defining
44
- # classes for each schema type, we don't have a way to register a custom subclass
45
- # to be used for fields.
46
- #
47
- # So, here we solve this a slightly different way: we prepend a module onto
48
- # the `GraphQL::Schema::Field class. This allows our module to act like a
49
- # decorator and intercept calls to `visible?` so that it can hide types as needed.
50
- module GraphQL
51
- class Schema
52
- class Field
53
- prepend ::ElasticGraph::GraphQL::MonkeyPatches::SchemaFieldVisibilityDecorator
54
- end
55
- end
56
- end
@@ -1,48 +0,0 @@
1
- # Copyright 2024 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
- require "graphql"
10
-
11
- module ElasticGraph
12
- class GraphQL
13
- module MonkeyPatches
14
- # This module is designed to monkey patch `GraphQL::Schema::Object`, but to do so in a
15
- # conservative, safe way:
16
- #
17
- # - It defines no new methods.
18
- # - It delegates to the original implementation with `super` unless we are sure that a type should be hidden.
19
- # - It only changes the behavior for ElasticGraph schemas (as indicated by `:elastic_graph_schema` in the `context`).
20
- module SchemaObjectVisibilityDecorator
21
- def visible?(context)
22
- if context[:elastic_graph_schema]&.type_named(graphql_name)&.hidden_from_queries?
23
- context[:elastic_graph_query_tracker].record_hidden_type(graphql_name)
24
- return false
25
- end
26
-
27
- super
28
- end
29
- end
30
- end
31
- end
32
- end
33
-
34
- # As per https://graphql-ruby.org/authorization/visibility.html, the public API
35
- # provided by the GraphQL gem to control visibility of object types is to define
36
- # a `visible?` class method on each of your type classes. However, because we load
37
- # our schema from an SDL definition rather than defining classes for each schema
38
- # type, we don't have a way to define the `visible?` on each of our type classes.
39
- #
40
- # So, here we solve this a slightly different way: we prepend a module onto
41
- # the `GraphQL::Schema::Object` singleton class. This allows our module to
42
- # act like a decorator and intercept calls to `visible?` so that it can hide
43
- # types as needed. This works because all types must be defined as subclasses
44
- # of `GraphQL::Schema::Object`, and in fact the GraphQL gem defined anonymous
45
- # subclasses for each type in our SDL schema, as you can see here:
46
- #
47
- # https://github.com/rmosolgo/graphql-ruby/blob/v1.12.16/lib/graphql/schema/build_from_definition.rb#L312
48
- GraphQL::Schema::Object.singleton_class.prepend ElasticGraph::GraphQL::MonkeyPatches::SchemaObjectVisibilityDecorator
@@ -1,114 +0,0 @@
1
- # Copyright 2024 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
- require "elastic_graph/graphql/resolvers/query_adapter"
10
-
11
- module ElasticGraph
12
- class GraphQL
13
- module Resolvers
14
- # Adapts the GraphQL gem's resolver interface to the interface implemented by
15
- # our resolvers. Responsible for routing a resolution request to the appropriate
16
- # resolver.
17
- class GraphQLAdapter
18
- def initialize(schema:, datastore_query_builder:, datastore_query_adapters:, runtime_metadata:, resolvers:)
19
- @schema = schema
20
- @query_adapter = QueryAdapter.new(
21
- datastore_query_builder: datastore_query_builder,
22
- datastore_query_adapters: datastore_query_adapters
23
- )
24
-
25
- @resolvers = resolvers
26
-
27
- scalar_types_by_name = runtime_metadata.scalar_types_by_name
28
- @coercion_adapters_by_scalar_type_name = ::Hash.new do |hash, name|
29
- scalar_types_by_name.fetch(name).load_coercion_adapter.extension_class
30
- end
31
- end
32
-
33
- # To be a valid resolver, we must implement `call`, accepting the 5 arguments listed here.
34
- #
35
- # See https://graphql-ruby.org/api-doc/1.9.6/GraphQL/Schema.html#from_definition-class_method
36
- # (specifically, the `default_resolve` argument) for the API documentation.
37
- def call(parent_type, field, object, args, context)
38
- schema_field = @schema.field_named(parent_type.graphql_name, field.name)
39
-
40
- # Extract the `:lookahead` extra that we have configured all fields to provide.
41
- # See https://graphql-ruby.org/api-doc/1.10.8/GraphQL/Execution/Lookahead.html for more info.
42
- # It is not a "real" arg in the schema and breaks `args_to_schema_form` when we call that
43
- # so we need to peel it off here.
44
- lookahead = args[:lookahead]
45
- # Convert args to the form they were defined in the schema, undoing the normalization
46
- # the GraphQL gem does to convert them to Ruby keyword args form.
47
- args = schema_field.args_to_schema_form(args.except(:lookahead))
48
-
49
- resolver = resolver_for(schema_field, object) do
50
- raise <<~ERROR
51
- No resolver yet implemented for this case.
52
-
53
- parent_type: #{schema_field.parent_type}
54
-
55
- field: #{schema_field}
56
-
57
- obj: #{object.inspect}
58
-
59
- args: #{args.inspect}
60
-
61
- ctx: #{context.inspect}
62
- ERROR
63
- end
64
-
65
- result = resolver.resolve(field: schema_field, object: object, args: args, context: context, lookahead: lookahead) do
66
- @query_adapter.build_query_from(field: schema_field, args: args, lookahead: lookahead, context: context)
67
- end
68
-
69
- # Give the field a chance to coerce the result before returning it. Initially, this is only used to deal with
70
- # enum value overrides (e.g. so that if `DayOfWeek.MONDAY` has been overridden to `DayOfWeek.MON`, we can coerce
71
- # a `MONDAY` value being returned by a painless script to `MON`), but this is designed to be general purpose
72
- # and we may use it for other coercions in the future.
73
- #
74
- # Note that coercion of scalar values is handled by the `coerce_result` callback below.
75
- schema_field.coerce_result(result)
76
- end
77
-
78
- # In order to support unions and interfaces, we must implement `resolve_type`.
79
- def resolve_type(supertype, object, context)
80
- # If `__typename` is available, use that to resolve. It should be available on any embedded abstract types...
81
- # (See `Inventor` in `config/schema.graphql` for an example of this kind of type union.)
82
- if (typename = object["__typename"])
83
- @schema.graphql_schema.possible_types(supertype).find { |t| t.graphql_name == typename }
84
- else
85
- # ...otherwise infer the type based on what index the object came from. This is the case
86
- # with unions/interfaces of individually indexed types.
87
- # (See `Part` in `config/schema/widgets.rb` for an example of this kind of type union.)
88
- @schema.document_type_stored_in(object.index_definition_name).graphql_type
89
- end
90
- end
91
-
92
- def coerce_input(type, value, ctx)
93
- scalar_coercion_adapter_for(type).coerce_input(value, ctx)
94
- end
95
-
96
- def coerce_result(type, value, ctx)
97
- scalar_coercion_adapter_for(type).coerce_result(value, ctx)
98
- end
99
-
100
- private
101
-
102
- def scalar_coercion_adapter_for(type)
103
- @coercion_adapters_by_scalar_type_name[type.graphql_name]
104
- end
105
-
106
- def resolver_for(field, object)
107
- return object if object.respond_to?(:can_resolve?) && object.can_resolve?(field: field, object: object)
108
- resolver = @resolvers.find { |r| r.can_resolve?(field: field, object: object) }
109
- resolver || yield
110
- end
111
- end
112
- end
113
- end
114
- end