Module: ElasticGraph::SchemaDefinition::Mixins::ImplementsInterfaces
- Included in:
- SchemaElements::InterfaceType, SchemaElements::ObjectType
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/implements_interfaces.rb
Overview
Mixin for types that can implement interfaces (SchemaElements::ObjectType and SchemaElements::InterfaceType).
Instance Method Summary collapse
-
#implemented_interfaces ⇒ Array<SchemaElements::TypeReference>
List of type references for the interface types implemented by this type.
-
#implements(*interface_names) ⇒ void
Declares that the current type implements the specified interface, making the current type a subtype of the interface.
-
#to_sdl {|SchemaElements::Argument| ... } ⇒ String
SDL string of the type.
Instance Method Details
#implemented_interfaces ⇒ Array<SchemaElements::TypeReference>
Returns list of type references for the interface types implemented by this type.
59 60 61 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/implements_interfaces.rb', line 59 def implemented_interfaces @implemented_interfaces ||= [] end |
#implements(*interface_names) ⇒ void
If the named interface has declared an index (via HasIndices#index), calling implements
causes this type to automatically inherit that index — it will be stored in the same datastore index as all other
implementations of the named interface. To use a dedicated index instead, call HasIndices#index on this type.
This method returns an undefined value.
Declares that the current type implements the specified interface, making the current type a subtype of the interface. The current type must define all of the fields of the named interface, with the exact same field types.
47 48 49 50 51 52 53 54 55 56 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/implements_interfaces.rb', line 47 def implements(*interface_names) interface_refs = interface_names.map do |interface_name| schema_def_state.type_ref(interface_name).to_final_form.tap do |interface_ref| implementations = schema_def_state.implementations_by_interface_ref[interface_ref] # : ::Set[SchemaElements::TypeWithSubfields] implementations << self end end implemented_interfaces.concat(interface_refs) end |
#to_sdl {|SchemaElements::Argument| ... } ⇒ String
Returns SDL string of the type.
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/implements_interfaces.rb', line 114 def to_sdl(&field_arg_selector) name_section = if implemented_interfaces.empty? name else # Include all ancestor interfaces in SDL all_interfaces = recursively_resolve_supertypes.grep(SchemaElements::InterfaceType) "#{name} implements #{all_interfaces.map(&:name).sort.join(" & ")}" end generate_sdl(name_section: name_section, &field_arg_selector) end |