elasticgraph-schema_definition 0.18.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +7 -0
  4. data/elasticgraph-schema_definition.gemspec +26 -0
  5. data/lib/elastic_graph/schema_definition/api.rb +359 -0
  6. data/lib/elastic_graph/schema_definition/factory.rb +506 -0
  7. data/lib/elastic_graph/schema_definition/indexing/derived_fields/append_only_set.rb +79 -0
  8. data/lib/elastic_graph/schema_definition/indexing/derived_fields/field_initializer_support.rb +59 -0
  9. data/lib/elastic_graph/schema_definition/indexing/derived_fields/immutable_value.rb +99 -0
  10. data/lib/elastic_graph/schema_definition/indexing/derived_fields/min_or_max_value.rb +62 -0
  11. data/lib/elastic_graph/schema_definition/indexing/derived_indexed_type.rb +346 -0
  12. data/lib/elastic_graph/schema_definition/indexing/event_envelope.rb +74 -0
  13. data/lib/elastic_graph/schema_definition/indexing/field.rb +181 -0
  14. data/lib/elastic_graph/schema_definition/indexing/field_reference.rb +51 -0
  15. data/lib/elastic_graph/schema_definition/indexing/field_type/enum.rb +65 -0
  16. data/lib/elastic_graph/schema_definition/indexing/field_type/object.rb +113 -0
  17. data/lib/elastic_graph/schema_definition/indexing/field_type/scalar.rb +51 -0
  18. data/lib/elastic_graph/schema_definition/indexing/field_type/union.rb +70 -0
  19. data/lib/elastic_graph/schema_definition/indexing/index.rb +318 -0
  20. data/lib/elastic_graph/schema_definition/indexing/json_schema_field_metadata.rb +34 -0
  21. data/lib/elastic_graph/schema_definition/indexing/json_schema_with_metadata.rb +234 -0
  22. data/lib/elastic_graph/schema_definition/indexing/list_counts_mapping.rb +53 -0
  23. data/lib/elastic_graph/schema_definition/indexing/relationship_resolver.rb +96 -0
  24. data/lib/elastic_graph/schema_definition/indexing/rollover_config.rb +25 -0
  25. data/lib/elastic_graph/schema_definition/indexing/update_target_factory.rb +54 -0
  26. data/lib/elastic_graph/schema_definition/indexing/update_target_resolver.rb +195 -0
  27. data/lib/elastic_graph/schema_definition/json_schema_pruner.rb +61 -0
  28. data/lib/elastic_graph/schema_definition/mixins/can_be_graphql_only.rb +31 -0
  29. data/lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb +119 -0
  30. data/lib/elastic_graph/schema_definition/mixins/has_directives.rb +65 -0
  31. data/lib/elastic_graph/schema_definition/mixins/has_documentation.rb +74 -0
  32. data/lib/elastic_graph/schema_definition/mixins/has_indices.rb +281 -0
  33. data/lib/elastic_graph/schema_definition/mixins/has_readable_to_s_and_inspect.rb +46 -0
  34. data/lib/elastic_graph/schema_definition/mixins/has_subtypes.rb +116 -0
  35. data/lib/elastic_graph/schema_definition/mixins/has_type_info.rb +181 -0
  36. data/lib/elastic_graph/schema_definition/mixins/implements_interfaces.rb +122 -0
  37. data/lib/elastic_graph/schema_definition/mixins/supports_default_value.rb +47 -0
  38. data/lib/elastic_graph/schema_definition/mixins/supports_filtering_and_aggregation.rb +267 -0
  39. data/lib/elastic_graph/schema_definition/mixins/verifies_graphql_name.rb +38 -0
  40. data/lib/elastic_graph/schema_definition/rake_tasks.rb +190 -0
  41. data/lib/elastic_graph/schema_definition/results.rb +404 -0
  42. data/lib/elastic_graph/schema_definition/schema_artifact_manager.rb +482 -0
  43. data/lib/elastic_graph/schema_definition/schema_elements/argument.rb +56 -0
  44. data/lib/elastic_graph/schema_definition/schema_elements/built_in_types.rb +1541 -0
  45. data/lib/elastic_graph/schema_definition/schema_elements/deprecated_element.rb +21 -0
  46. data/lib/elastic_graph/schema_definition/schema_elements/directive.rb +40 -0
  47. data/lib/elastic_graph/schema_definition/schema_elements/enum_type.rb +189 -0
  48. data/lib/elastic_graph/schema_definition/schema_elements/enum_value.rb +73 -0
  49. data/lib/elastic_graph/schema_definition/schema_elements/enum_value_namer.rb +89 -0
  50. data/lib/elastic_graph/schema_definition/schema_elements/enums_for_indexed_types.rb +82 -0
  51. data/lib/elastic_graph/schema_definition/schema_elements/field.rb +1085 -0
  52. data/lib/elastic_graph/schema_definition/schema_elements/field_path.rb +112 -0
  53. data/lib/elastic_graph/schema_definition/schema_elements/field_source.rb +16 -0
  54. data/lib/elastic_graph/schema_definition/schema_elements/graphql_sdl_enumerator.rb +113 -0
  55. data/lib/elastic_graph/schema_definition/schema_elements/input_field.rb +31 -0
  56. data/lib/elastic_graph/schema_definition/schema_elements/input_type.rb +60 -0
  57. data/lib/elastic_graph/schema_definition/schema_elements/interface_type.rb +72 -0
  58. data/lib/elastic_graph/schema_definition/schema_elements/list_counts_state.rb +40 -0
  59. data/lib/elastic_graph/schema_definition/schema_elements/object_type.rb +53 -0
  60. data/lib/elastic_graph/schema_definition/schema_elements/relationship.rb +218 -0
  61. data/lib/elastic_graph/schema_definition/schema_elements/scalar_type.rb +310 -0
  62. data/lib/elastic_graph/schema_definition/schema_elements/sort_order_enum_value.rb +36 -0
  63. data/lib/elastic_graph/schema_definition/schema_elements/sub_aggregation_path.rb +66 -0
  64. data/lib/elastic_graph/schema_definition/schema_elements/type_namer.rb +237 -0
  65. data/lib/elastic_graph/schema_definition/schema_elements/type_reference.rb +353 -0
  66. data/lib/elastic_graph/schema_definition/schema_elements/type_with_subfields.rb +579 -0
  67. data/lib/elastic_graph/schema_definition/schema_elements/union_type.rb +157 -0
  68. data/lib/elastic_graph/schema_definition/scripting/file_system_repository.rb +77 -0
  69. data/lib/elastic_graph/schema_definition/scripting/script.rb +48 -0
  70. data/lib/elastic_graph/schema_definition/scripting/scripts/field/as_day_of_week.painless +24 -0
  71. data/lib/elastic_graph/schema_definition/scripting/scripts/field/as_time_of_day.painless +41 -0
  72. data/lib/elastic_graph/schema_definition/scripting/scripts/filter/by_time_of_day.painless +22 -0
  73. data/lib/elastic_graph/schema_definition/scripting/scripts/update/index_data.painless +93 -0
  74. data/lib/elastic_graph/schema_definition/state.rb +212 -0
  75. data/lib/elastic_graph/schema_definition/test_support.rb +113 -0
  76. metadata +513 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47ae5c55ab0b2b648a5f0df3d5648e842c31f5426865cef9a2ef4f9cf51269bb
4
+ data.tar.gz: a0c1ded435206b9ba3afa2a049cd262c5f31046aa750401a2797292f5b8211c8
5
+ SHA512:
6
+ metadata.gz: adf50d9102ca7a6eeb5024d0b4dad9ae81579bb4a4eb19a46355c3d92b7e337c566a8d352f6298c38600a56189b6e31749f63d15690071405430ee46ab212a72
7
+ data.tar.gz: 984cdaed0275b0c37896f733448b9a7039aaf7cbd4b13ce8eb8f0c9b47725e22b6e2836984eaed66bd6fe866ab0690e6a30816c2f940b3f6c828e4ad1a728154
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Block, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # ElasticGraph::SchemaDefinition
2
+
3
+ Provides the ElasticGraph schema definition API, which is used to
4
+ generate ElasticGraph's schema artifacts.
5
+
6
+ This gem is not intended to be used in production--production should
7
+ just use the schema artifacts instead.
@@ -0,0 +1,26 @@
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_relative "../gemspec_helper"
10
+
11
+ ElasticGraphGemspecHelper.define_elasticgraph_gem(gemspec_file: __FILE__, category: :local) do |spec, eg_version|
12
+ spec.summary = "ElasticGraph gem that provides the schema definition API and generates schema artifacts."
13
+
14
+ spec.add_dependency "elasticgraph-graphql", eg_version # needed since we validate that scalar `coerce_with` options are valid (which loads scalar coercion adapters)
15
+ spec.add_dependency "elasticgraph-indexer", eg_version # needed since we validate that scalar `prepare_for_indexing_with` options are valid (which loads indexing preparer adapters)
16
+ spec.add_dependency "elasticgraph-json_schema", eg_version
17
+ spec.add_dependency "elasticgraph-schema_artifacts", eg_version
18
+ spec.add_dependency "elasticgraph-support", eg_version
19
+ spec.add_dependency "graphql", ">= 2.3.7", "< 2.4"
20
+ spec.add_dependency "rake", "~> 13.2"
21
+
22
+ spec.add_development_dependency "elasticgraph-admin", eg_version
23
+ spec.add_development_dependency "elasticgraph-datastore_core", eg_version
24
+ spec.add_development_dependency "elasticgraph-elasticsearch", eg_version
25
+ spec.add_development_dependency "elasticgraph-opensearch", eg_version
26
+ end
@@ -0,0 +1,359 @@
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/error"
10
+ require "elastic_graph/schema_artifacts/runtime_metadata/extension"
11
+ require "elastic_graph/schema_definition/mixins/has_readable_to_s_and_inspect"
12
+ require "elastic_graph/schema_definition/results"
13
+ require "elastic_graph/schema_definition/state"
14
+
15
+ module ElasticGraph
16
+ # The main entry point for schema definition from ElasticGraph applications.
17
+ #
18
+ # Call this API from a Ruby file configured as the `path_to_schema` (or from a Ruby file
19
+ # `load`ed from the `path_to_schema` file).
20
+ #
21
+ # @example
22
+ # ElasticGraph.define_schema do |schema|
23
+ # # The `schema` object provides the schema definition API. Use it in this block.
24
+ # end
25
+ def self.define_schema
26
+ if (api_instance = ::Thread.current[:ElasticGraph_SchemaDefinition_API_instance])
27
+ yield api_instance
28
+ else
29
+ raise SchemaError, "No active `SchemaDefinition::API` instance is available. " \
30
+ "Let ElasticGraph load the schema definition files."
31
+ end
32
+ end
33
+
34
+ # Provides the ElasticGraph schema definition API. The primary entry point is {.define_schema}.
35
+ module SchemaDefinition
36
+ # Root API object that provides the schema definition API.
37
+ #
38
+ # @example
39
+ # ElasticGraph.define_schema do |schema|
40
+ # # The `schema` object is an instance of `API`
41
+ # end
42
+ class API
43
+ include Mixins::HasReadableToSAndInspect.new
44
+
45
+ # @dynamic state, factory
46
+
47
+ # @return [State] object which holds all state for the schema definition
48
+ attr_reader :state
49
+
50
+ # @return [Factory] object responsible for instantiating all schema element classes
51
+ attr_reader :factory
52
+
53
+ # @private
54
+ def initialize(
55
+ schema_elements,
56
+ index_document_sizes,
57
+ extension_modules: [],
58
+ derived_type_name_formats: {},
59
+ type_name_overrides: {},
60
+ enum_value_overrides_by_type: {},
61
+ output: $stdout
62
+ )
63
+ @state = State.with(
64
+ api: self,
65
+ schema_elements: schema_elements,
66
+ index_document_sizes: index_document_sizes,
67
+ derived_type_name_formats: derived_type_name_formats,
68
+ type_name_overrides: type_name_overrides,
69
+ enum_value_overrides_by_type: enum_value_overrides_by_type,
70
+ output: output
71
+ )
72
+
73
+ @factory = @state.factory
74
+
75
+ extension_modules.each { |mod| extend(mod) }
76
+
77
+ # These lines must come _after_ the extension modules are applied, so that the extension modules
78
+ # have a chance to hook into the factory in order to customize built in types if desired.
79
+ @factory.new_built_in_types(self).register_built_in_types
80
+ @state.initially_registered_built_in_types.merge(@state.types_by_name.keys)
81
+ end
82
+
83
+ # Defines a raw GraphQL SDL snippet that will be included in the generated `schema.graphql` artifact. Designed to be an escape hatch,
84
+ # for when ElasticGraph doesn’t provide another way to write some type of GraphQL SDL element that you need. Currently, the only
85
+ # known use case is to define custom GraphQL directives.
86
+ #
87
+ # @param string [String] Raw snippet of SDL
88
+ # @return [void]
89
+ #
90
+ # @example Define a custom directive and use it
91
+ # ElasticGraph.define_schema do |schema|
92
+ # # Define a directive we can use to annotate what system a data type comes from.
93
+ # schema.raw_sdl "directive @sourcedFrom(system: String!) on OBJECT"
94
+ #
95
+ # schema.object_type "Transaction" do |t|
96
+ # t.directive "sourcedFrom", system: "transaction-processor"
97
+ # end
98
+ # end
99
+ def raw_sdl(string)
100
+ @state.sdl_parts << string
101
+ nil
102
+ end
103
+
104
+ # Defines a [GraphQL object type](https://graphql.org/learn/schema/#object-types-and-fields) Use it to define a concrete type that
105
+ # has subfields. Object types can either be _indexed_ (e.g. directly indexed in the datastore, and available to query from the
106
+ # root `Query` object) or _embedded_ in other indexed types.
107
+ #
108
+ # @param name [String] name of the object type
109
+ # @yield [SchemaElements::ObjectType] object type object
110
+ # @return [void]
111
+ #
112
+ # @example Define embedded and indexed object types
113
+ # ElasticGraph.define_schema do |schema|
114
+ # # `Money` is an embedded object type
115
+ # schema.object_type "Money" do |t|
116
+ # t.field "currency", "String"
117
+ # t.field "amount", "JsonSafeLong"
118
+ # end
119
+ #
120
+ # # `Transaction` is an indexed object type
121
+ # schema.object_type "Transaction" do |t|
122
+ # t.root_query_fields plural: "transactions"
123
+ # t.field "id", "ID"
124
+ # t.field "cost", "Money"
125
+ # t.index "transactions"
126
+ # end
127
+ # end
128
+ def object_type(name, &block)
129
+ @state.register_object_interface_or_union_type @factory.new_object_type(name.to_s, &block)
130
+ nil
131
+ end
132
+
133
+ # Defines a [GraphQL interface](https://graphql.org/learn/schema/#interfaces). Use it to define an abstract supertype with
134
+ # one or more fields that concrete implementations of the interface must also define. Each implementation can be an
135
+ # {SchemaElements::ObjectType} or {SchemaElements::InterfaceType}.
136
+ #
137
+ # @param name [String] name of the interface
138
+ # @yield [SchemaElements::InterfaceType] interface type object
139
+ # @return [void]
140
+ #
141
+ # @example Define an interface and implement it
142
+ # ElasticGraph.define_schema do |schema|
143
+ # schema.interface_type "Athlete" do |t|
144
+ # t.field "name", "String"
145
+ # t.field "team", "String"
146
+ # end
147
+ #
148
+ # schema.object_type "BaseballPlayer" do |t|
149
+ # t.implements "Athlete"
150
+ # t.field "name", "String"
151
+ # t.field "team", "String"
152
+ # t.field "battingAvg", "Float"
153
+ # end
154
+ #
155
+ # schema.object_type "BasketballPlayer" do |t|
156
+ # t.implements "Athlete"
157
+ # t.field "name", "String"
158
+ # t.field "team", "String"
159
+ # t.field "pointsPerGame", "Float"
160
+ # end
161
+ # end
162
+ def interface_type(name, &block)
163
+ @state.register_object_interface_or_union_type @factory.new_interface_type(name.to_s, &block)
164
+ nil
165
+ end
166
+
167
+ # Defines a [GraphQL enum type](https://graphql.org/learn/schema/#enumeration-types).
168
+ # The type is restricted to an enumerated set of values, each with a unique name.
169
+ # Use `value` or `values` to define the enum values in the passed block.
170
+ #
171
+ # Note: if required by your configuration, this may generate a pair of Enum types (an input
172
+ # enum and an output enum).
173
+ #
174
+ # @param name [String] name of the enum type
175
+ # @yield [SchemaElements::EnumType] enum type object
176
+ # @return [void]
177
+ #
178
+ # @example Define an enum type
179
+ # ElasticGraph.define_schema do |schema|
180
+ # schema.enum_type "Currency" do |t|
181
+ # t.value "USD" do |v|
182
+ # v.documentation "US Dollars."
183
+ # end
184
+ #
185
+ # t.value "JPY" do |v|
186
+ # v.documentation "Japanese Yen."
187
+ # end
188
+ #
189
+ # # You can define multiple values in one call if you don't care about their docs or directives.
190
+ # t.values "GBP", "AUD"
191
+ # end
192
+ # end
193
+ def enum_type(name, &block)
194
+ @state.register_enum_type @factory.new_enum_type(name.to_s, &block)
195
+ nil
196
+ end
197
+
198
+ # Defines a [GraphQL union type](https://graphql.org/learn/schema/#union-types). Use it to define an abstract supertype with one or
199
+ # more concrete subtypes. Each subtype must be an {SchemaElements::ObjectType}, but they do not have to share any fields in common.
200
+ #
201
+ # @param name [String] name of the union type
202
+ # @yield [SchemaElements::UnionType] union type object
203
+ # @return [void]
204
+ #
205
+ # @example Define a union type
206
+ # ElasticGraph.define_schema do |schema|
207
+ # schema.object_type "Card" do |t|
208
+ # # ...
209
+ # end
210
+ #
211
+ # schema.object_type "BankAccount" do |t|
212
+ # # ...
213
+ # end
214
+ #
215
+ # schema.object_type "BitcoinWallet" do |t|
216
+ # # ...
217
+ # end
218
+ #
219
+ # schema.union_type "FundingSource" do |t|
220
+ # t.subtype "Card"
221
+ # t.subtypes "BankAccount", "BitcoinWallet"
222
+ # end
223
+ # end
224
+ def union_type(name, &block)
225
+ @state.register_object_interface_or_union_type @factory.new_union_type(name.to_s, &block)
226
+ nil
227
+ end
228
+
229
+ # Defines a [GraphQL scalar type](https://graphql.org/learn/schema/#scalar-types). ElasticGraph itself uses this to define a few
230
+ # common scalar types (e.g. `Date` and `DateTime`), but it is also available to you to use to define your own custom scalar types.
231
+ #
232
+ # @param name [String] name of the scalar type
233
+ # @yield [SchemaElements::ScalarType] scalar type object
234
+ # @return [void]
235
+ #
236
+ # @example Define a scalar type
237
+ # ElasticGraph.define_schema do |schema|
238
+ # schema.scalar_type "URL" do |t|
239
+ # t.mapping type: "keyword"
240
+ # t.json_schema type: "string", format: "uri"
241
+ # end
242
+ # end
243
+ def scalar_type(name, &block)
244
+ @state.register_scalar_type @factory.new_scalar_type(name.to_s, &block)
245
+ nil
246
+ end
247
+
248
+ # Registers the name of a type that existed in a prior version of the schema but has been deleted.
249
+ #
250
+ # @note In situations where this API applies, ElasticGraph will give you an error message indicating that you need to use this API
251
+ # or {SchemaElements::TypeWithSubfields#renamed_from}. Likewise, when ElasticGraph no longer needs to know about this, it'll give you a warning
252
+ # indicating the call to this method can be removed.
253
+ #
254
+ # @param name [String] name of type that used to exist but has been deleted
255
+ # @return [void]
256
+ #
257
+ # @example Indicate that `Widget` has been deleted
258
+ # ElasticGraph.define_schema do |schema|
259
+ # schema.deleted_type "Widget"
260
+ # end
261
+ def deleted_type(name)
262
+ @state.register_deleted_type(
263
+ name,
264
+ defined_at: caller_locations(1, 1).first, # : ::Thread::Backtrace::Location
265
+ defined_via: %(schema.deleted_type "#{name}")
266
+ )
267
+ nil
268
+ end
269
+
270
+ # Registers a GraphQL extension module that will be loaded and used by `elasticgraph-graphql`. While such
271
+ # extension modules can also be configured in a settings YAML file, it can be useful to register it here
272
+ # when you want to ensure that the extension is used in all environments. For example, an extension library
273
+ # that defines custom schema elements (such as `elasticgraph-apollo`) may need to ensure its corresponding
274
+ # GraphQL extension module is used since the custom schema elements would not work correctly otherwise.
275
+ #
276
+ # @param extension_module [Module] GraphQL extension module
277
+ # @param defined_at [String] the `require` path of the extension module
278
+ # @param extension_config [Hash<Symbol, Object>] configuration options for the extension module
279
+ # @return [void]
280
+ #
281
+ # @example Register `elasticgraph-query_registry` extension module
282
+ # require(query_registry_require_path = "elastic_graph/query_registry/graphql_extension")
283
+ #
284
+ # ElasticGraph.define_schema do |schema|
285
+ # schema.register_graphql_extension ElasticGraph::QueryRegistry::GraphQLExtension,
286
+ # defined_at: query_registry_require_path
287
+ # end
288
+ def register_graphql_extension(extension_module, defined_at:, **extension_config)
289
+ @state.graphql_extension_modules << SchemaArtifacts::RuntimeMetadata::Extension.new(extension_module, defined_at, extension_config)
290
+ nil
291
+ end
292
+
293
+ # @return the results of the schema definition
294
+ def results
295
+ @results ||= Results.new(@state)
296
+ end
297
+
298
+ # Defines the version number of the current JSON schema. Importantly, every time a change is made that impacts the JSON schema
299
+ # artifact, the version number must be incremented to ensure that each different version of the JSON schema is identified by a unique
300
+ # version number. The publisher will then include this version number in published events to identify the version of the schema it
301
+ # was using. This avoids the need to deploy the publisher and ElasticGraph indexer at the same time to keep them in sync.
302
+ #
303
+ # @note While this is an important part of how ElasticGraph is designed to support schema evolution, it can be annoying constantly
304
+ # have to increment this while rapidly changing the schema during prototyping. You can disable the requirement to increment this
305
+ # on every JSON schema change by setting `enforce_json_schema_version` to `false` in your `Rakefile`.
306
+ #
307
+ # @param version [Integer] current version number of the JSON schema artifact
308
+ # @return [void]
309
+ # @see Local::RakeTasks#enforce_json_schema_version
310
+ #
311
+ # @example Set the JSON schema version to 1
312
+ # ElasticGraph.define_schema do |schema|
313
+ # schema.json_schema_version 1
314
+ # end
315
+ def json_schema_version(version)
316
+ if !version.is_a?(Integer) || version < 1
317
+ raise SchemaError, "`json_schema_version` must be a positive integer. Specified version: #{version}"
318
+ end
319
+
320
+ if @state.json_schema_version
321
+ raise SchemaError, "`json_schema_version` can only be set once on a schema. Previously-set version: #{@state.json_schema_version}"
322
+ end
323
+
324
+ @state.json_schema_version = version
325
+ @state.json_schema_version_setter_location = caller_locations(1, 1).to_a.first
326
+ nil
327
+ end
328
+
329
+ # Registers a customization callback that will be applied to every built-in type automatically provided by ElasticGraph. Provides
330
+ # an opportunity to customize the built-in types (e.g. to add directives to them or whatever).
331
+ #
332
+ # @yield [SchemaElements::EnumType, SchemaElements::InputType, SchemaElements::InterfaceType, SchemaElements::ObjectType, SchemaElements::ScalarType, SchemaElements::UnionType] built in type
333
+ # @return [void]
334
+ #
335
+ # @example Customize documentation of built-in types
336
+ # ElasticGraph.define_schema do |schema|
337
+ # schema.on_built_in_types do |type|
338
+ # type.append_to_documentation "This is a built-in ElasticGraph type."
339
+ # end
340
+ # end
341
+ def on_built_in_types(&customization_block)
342
+ @state.built_in_types_customization_blocks << customization_block
343
+ nil
344
+ end
345
+
346
+ # While the block executes, makes any `ElasticGraph.define_schema` calls operate on this `API` instance.
347
+ #
348
+ # @private
349
+ def as_active_instance
350
+ # @type var old_value: API?
351
+ old_value = ::Thread.current[:ElasticGraph_SchemaDefinition_API_instance]
352
+ ::Thread.current[:ElasticGraph_SchemaDefinition_API_instance] = self
353
+ yield
354
+ ensure
355
+ ::Thread.current[:ElasticGraph_SchemaDefinition_API_instance] = old_value
356
+ end
357
+ end
358
+ end
359
+ end