Class: ElasticGraph::SchemaDefinition::State
- Inherits:
-
Struct
- Object
- Struct
- ElasticGraph::SchemaDefinition::State
- Defined in:
- lib/elastic_graph/schema_definition/state.rb
Overview
Encapsulates all state that needs to be managed while a schema is defined. This is separated from ‘API` to make it easy to expose some state management helper methods to our internal code without needing to expose it as part of the public API.
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
-
#built_in_types_customization_blocks ⇒ Object
Returns the value of attribute built_in_types_customization_blocks.
-
#deleted_fields_by_type_name_and_old_field_name ⇒ Object
Returns the value of attribute deleted_fields_by_type_name_and_old_field_name.
-
#deleted_types_by_old_name ⇒ Object
Returns the value of attribute deleted_types_by_old_name.
-
#enum_types_by_name ⇒ Object
Returns the value of attribute enum_types_by_name.
-
#enum_value_namer ⇒ Object
Returns the value of attribute enum_value_namer.
-
#graphql_extension_modules ⇒ Object
Returns the value of attribute graphql_extension_modules.
-
#implementations_by_interface_ref ⇒ Object
Returns the value of attribute implementations_by_interface_ref.
-
#index_document_sizes ⇒ Object
(also: #index_document_sizes?)
Returns the value of attribute index_document_sizes.
-
#initially_registered_built_in_types ⇒ Object
Returns the value of attribute initially_registered_built_in_types.
-
#json_schema_version ⇒ Object
Returns the value of attribute json_schema_version.
-
#json_schema_version_setter_location ⇒ Object
Returns the value of attribute json_schema_version_setter_location.
-
#object_types_by_name ⇒ Object
Returns the value of attribute object_types_by_name.
-
#output ⇒ Object
Returns the value of attribute output.
-
#paginated_collection_element_types ⇒ Object
Returns the value of attribute paginated_collection_element_types.
-
#renamed_fields_by_type_name_and_old_field_name ⇒ Object
Returns the value of attribute renamed_fields_by_type_name_and_old_field_name.
-
#renamed_types_by_old_name ⇒ Object
Returns the value of attribute renamed_types_by_old_name.
-
#scalar_types_by_name ⇒ Object
Returns the value of attribute scalar_types_by_name.
-
#schema_elements ⇒ Object
Returns the value of attribute schema_elements.
-
#sdl_parts ⇒ Object
Returns the value of attribute sdl_parts.
-
#sub_aggregation_paths_by_type ⇒ Object
Returns the value of attribute sub_aggregation_paths_by_type.
-
#type_namer ⇒ Object
Returns the value of attribute type_namer.
-
#type_refs_by_name ⇒ Object
Returns the value of attribute type_refs_by_name.
-
#types_by_name ⇒ Object
Returns the value of attribute types_by_name.
-
#user_defined_fields ⇒ Object
Returns the value of attribute user_defined_fields.
-
#user_definition_complete ⇒ Object
Returns the value of attribute user_definition_complete.
Class Method Summary collapse
Instance Method Summary collapse
- #enums_for_indexed_types ⇒ Object
- #factory ⇒ Object
- #register_deleted_field(type_name, field_name, defined_at:, defined_via:) ⇒ Object
- #register_deleted_type(type_name, defined_at:, defined_via:) ⇒ Object
- #register_enum_type(type) ⇒ Object
- #register_input_type(type) ⇒ Object
- #register_object_interface_or_union_type(type) ⇒ Object
- #register_renamed_field(type_name, from:, to:, defined_at:, defined_via:) ⇒ Object
- #register_renamed_type(type_name, from:, defined_at:, defined_via:) ⇒ Object
- #register_scalar_type(type) ⇒ Object
-
#register_user_defined_field(field) ⇒ Object
Registers the given ‘field` as a user-defined field, unless the user definitions are complete.
- #sub_aggregation_paths_for(type) ⇒ Object
- #type_ref(name) ⇒ Object
- #user_defined_field_references_by_type_name ⇒ Object
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def api @api end |
#built_in_types_customization_blocks ⇒ Object
Returns the value of attribute built_in_types_customization_blocks
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def built_in_types_customization_blocks @built_in_types_customization_blocks end |
#deleted_fields_by_type_name_and_old_field_name ⇒ Object
Returns the value of attribute deleted_fields_by_type_name_and_old_field_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def deleted_fields_by_type_name_and_old_field_name @deleted_fields_by_type_name_and_old_field_name end |
#deleted_types_by_old_name ⇒ Object
Returns the value of attribute deleted_types_by_old_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def deleted_types_by_old_name @deleted_types_by_old_name end |
#enum_types_by_name ⇒ Object
Returns the value of attribute enum_types_by_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def enum_types_by_name @enum_types_by_name end |
#enum_value_namer ⇒ Object
Returns the value of attribute enum_value_namer
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def enum_value_namer @enum_value_namer end |
#graphql_extension_modules ⇒ Object
Returns the value of attribute graphql_extension_modules
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def graphql_extension_modules @graphql_extension_modules end |
#implementations_by_interface_ref ⇒ Object
Returns the value of attribute implementations_by_interface_ref
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def implementations_by_interface_ref @implementations_by_interface_ref end |
#index_document_sizes ⇒ Object Also known as: index_document_sizes?
Returns the value of attribute index_document_sizes
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def index_document_sizes @index_document_sizes end |
#initially_registered_built_in_types ⇒ Object
Returns the value of attribute initially_registered_built_in_types
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def initially_registered_built_in_types @initially_registered_built_in_types end |
#json_schema_version ⇒ Object
Returns the value of attribute json_schema_version
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def json_schema_version @json_schema_version end |
#json_schema_version_setter_location ⇒ Object
Returns the value of attribute json_schema_version_setter_location
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def json_schema_version_setter_location @json_schema_version_setter_location end |
#object_types_by_name ⇒ Object
Returns the value of attribute object_types_by_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def object_types_by_name @object_types_by_name end |
#output ⇒ Object
Returns the value of attribute output
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def output @output end |
#paginated_collection_element_types ⇒ Object
Returns the value of attribute paginated_collection_element_types
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def paginated_collection_element_types @paginated_collection_element_types end |
#renamed_fields_by_type_name_and_old_field_name ⇒ Object
Returns the value of attribute renamed_fields_by_type_name_and_old_field_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def renamed_fields_by_type_name_and_old_field_name @renamed_fields_by_type_name_and_old_field_name end |
#renamed_types_by_old_name ⇒ Object
Returns the value of attribute renamed_types_by_old_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def renamed_types_by_old_name @renamed_types_by_old_name end |
#scalar_types_by_name ⇒ Object
Returns the value of attribute scalar_types_by_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def scalar_types_by_name @scalar_types_by_name end |
#schema_elements ⇒ Object
Returns the value of attribute schema_elements
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def schema_elements @schema_elements end |
#sdl_parts ⇒ Object
Returns the value of attribute sdl_parts
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def sdl_parts @sdl_parts end |
#sub_aggregation_paths_by_type ⇒ Object
Returns the value of attribute sub_aggregation_paths_by_type
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def sub_aggregation_paths_by_type @sub_aggregation_paths_by_type end |
#type_namer ⇒ Object
Returns the value of attribute type_namer
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def type_namer @type_namer end |
#type_refs_by_name ⇒ Object
Returns the value of attribute type_refs_by_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def type_refs_by_name @type_refs_by_name end |
#types_by_name ⇒ Object
Returns the value of attribute types_by_name
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def types_by_name @types_by_name end |
#user_defined_fields ⇒ Object
Returns the value of attribute user_defined_fields
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def user_defined_fields @user_defined_fields end |
#user_definition_complete ⇒ Object
Returns the value of attribute user_definition_complete
25 26 27 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 25 def user_definition_complete @user_definition_complete end |
Class Method Details
.with(api:, schema_elements:, index_document_sizes:, derived_type_name_formats:, type_name_overrides:, enum_value_overrides_by_type:, output: $stdout) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 55 def self.with( api:, schema_elements:, index_document_sizes:, derived_type_name_formats:, type_name_overrides:, enum_value_overrides_by_type:, output: $stdout ) # @type var types_by_name: SchemaElements::typesByNameHash types_by_name = {} new( api: api, schema_elements: schema_elements, index_document_sizes: index_document_sizes, types_by_name: types_by_name, object_types_by_name: {}, scalar_types_by_name: {}, enum_types_by_name: {}, implementations_by_interface_ref: ::Hash.new { |h, k| h[k] = ::Set.new }, sdl_parts: [], paginated_collection_element_types: ::Set.new, user_defined_fields: ::Set.new, renamed_types_by_old_name: {}, deleted_types_by_old_name: {}, renamed_fields_by_type_name_and_old_field_name: ::Hash.new { |h, k| h[k] = {} }, deleted_fields_by_type_name_and_old_field_name: ::Hash.new { |h, k| h[k] = {} }, json_schema_version_setter_location: nil, json_schema_version: nil, graphql_extension_modules: [], initially_registered_built_in_types: ::Set.new, built_in_types_customization_blocks: [], user_definition_complete: false, sub_aggregation_paths_by_type: {}, type_refs_by_name: {}, type_namer: SchemaElements::TypeNamer.new( format_overrides: derived_type_name_formats, name_overrides: type_name_overrides ), enum_value_namer: SchemaElements::EnumValueNamer.new(enum_value_overrides_by_type), output: output ) end |
Instance Method Details
#enums_for_indexed_types ⇒ Object
177 178 179 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 177 def enums_for_indexed_types @enums_for_indexed_types ||= factory.new_enums_for_indexed_types end |
#factory ⇒ Object
173 174 175 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 173 def factory @factory ||= Factory.new(self) end |
#register_deleted_field(type_name, field_name, defined_at:, defined_via:) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 149 def register_deleted_field(type_name, field_name, defined_at:, defined_via:) deleted_fields_by_type_name_and_old_field_name[type_name][field_name] = factory.new_deprecated_element( field_name, defined_at: defined_at, defined_via: defined_via ) end |
#register_deleted_type(type_name, defined_at:, defined_via:) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 133 def register_deleted_type(type_name, defined_at:, defined_via:) deleted_types_by_old_name[type_name] = factory.new_deprecated_element( type_name, defined_at: defined_at, defined_via: defined_via ) end |
#register_enum_type(type) ⇒ Object
113 114 115 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 113 def register_enum_type(type) register_type(type, enum_types_by_name) end |
#register_input_type(type) ⇒ Object
121 122 123 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 121 def register_input_type(type) register_type(type) end |
#register_object_interface_or_union_type(type) ⇒ Object
109 110 111 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 109 def register_object_interface_or_union_type(type) register_type(type, object_types_by_name) end |
#register_renamed_field(type_name, from:, to:, defined_at:, defined_via:) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 141 def register_renamed_field(type_name, from:, to:, defined_at:, defined_via:) renamed_fields_by_type_name_and_old_field_name[type_name][from] = factory.new_deprecated_element( to, defined_at: defined_at, defined_via: defined_via ) end |
#register_renamed_type(type_name, from:, defined_at:, defined_via:) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 125 def register_renamed_type(type_name, from:, defined_at:, defined_via:) renamed_types_by_old_name[from] = factory.new_deprecated_element( type_name, defined_at: defined_at, defined_via: defined_via ) end |
#register_scalar_type(type) ⇒ Object
117 118 119 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 117 def register_scalar_type(type) register_type(type, scalar_types_by_name) end |
#register_user_defined_field(field) ⇒ Object
Registers the given ‘field` as a user-defined field, unless the user definitions are complete.
158 159 160 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 158 def register_user_defined_field(field) user_defined_fields << field end |
#sub_aggregation_paths_for(type) ⇒ Object
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 181 def sub_aggregation_paths_for(type) sub_aggregation_paths_by_type.fetch(type) do SchemaElements::SubAggregationPath.paths_for(type, schema_def_state: self).uniq.tap do |paths| # Cache our results if the user has finished their schema definition. Otherwise, it's not safe to cache. # :nocov: -- we never execute this with `user_definition_complete == false` sub_aggregation_paths_by_type[type] = paths if user_definition_complete # :nocov: end end end |
#type_ref(name) ⇒ Object
103 104 105 106 107 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 103 def type_ref(name) # Type references are immutable and can be safely cached. Here we cache them because we've observed # it having a noticeable impact on our test suite runtime. type_refs_by_name[name] ||= factory.new_type_reference(name) end |
#user_defined_field_references_by_type_name ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/elastic_graph/schema_definition/state.rb', line 162 def user_defined_field_references_by_type_name @user_defined_field_references_by_type_name ||= begin unless user_definition_complete raise Errors::SchemaError, "Cannot access `user_defined_field_references_by_type_name` until the schema definition is complete." end @user_defined_field_references_by_type_name ||= user_defined_fields .group_by { |f| f.type.fully_unwrapped.name } end end |