Class: ElasticGraph::SchemaDefinition::SchemaElements::InterfaceType

Inherits:
TypeWithSubfields
  • Object
show all
Includes:
Mixins::HasIndices, Mixins::HasSubtypes, Mixins::ImplementsInterfaces, Mixins::SupportsFilteringAndAggregation
Defined in:
lib/elastic_graph/schema_definition/schema_elements/interface_type.rb

Overview

Defines a [GraphQL interface](graphql.org/learn/schema/#interfaces). Use it to define an abstract supertype with one or more fields that concrete implementations of the interface must also define. Each implementation can be an ObjectType or InterfaceType.

Examples:

Define an interface

ElasticGraph.define_schema do |schema|
  schema.interface_type "Athlete" do |t|
    # in the block, `t` is an InterfaceType
  end
end

Constant Summary

Constants included from Mixins::HasTypeInfo

Mixins::HasTypeInfo::CUSTOMIZABLE_DATASTORE_PARAMS

Instance Attribute Summary

Attributes included from Mixins::HasIndices

#runtime_metadata_overrides

Attributes inherited from TypeWithSubfields

#field_factory, #indexing_fields_by_name_in_index, #relay_pagination_type, #reserved_field_names, #schema_def_state, #schema_kind, #type_ref, #wrapping_type

Attributes included from Mixins::HasDocumentation

#doc_comment

Instance Method Summary collapse

Methods included from Mixins::HasSubtypes

#abstract?, #current_sources, #index_field_runtime_metadata_tuples, #indexed?, #indexing_fields_by_name_in_index, #recursively_resolve_subtypes, #to_indexing_field_type

Methods included from Mixins::HasIndices

#abstract?, #derive_indexed_type_fields, #derived_indexed_types, #fields_with_sources, #index, #indexed?, #indices, #plural_root_query_field_name, #root_query_fields, #root_query_fields_customizations, #runtime_metadata, #singular_root_query_field_name

Methods included from Mixins::SupportsFilteringAndAggregation

#derived_graphql_types, #does_not_support?, #has_custom_mapping_type?, #supports?

Methods included from Mixins::ImplementsInterfaces

#implemented_interfaces, #implements, #to_sdl, #verify_graphql_correctness!

Methods inherited from TypeWithSubfields

#aggregated_values_type, #current_sources, #deleted_field, #field, #generate_sdl, #index_field_runtime_metadata_tuples, #indexed?, #name, #paginated_collection_field, #relates_to_many, #relates_to_one, #renamed_from, #to_indexing_field_type, #to_sdl

Methods included from Mixins::HasTypeInfo

#json_schema, #json_schema_options, #mapping, #mapping_options

Methods included from Mixins::HasDerivedGraphQLTypeCustomizations

#customize_derived_type_fields, #customize_derived_types, #derived_field_customizations_by_name_for_type, #derived_field_customizations_by_type_and_field_name, #derived_type_customizations_by_name, #derived_type_customizations_for_type

Methods included from Mixins::HasDirectives

#directive, #directives, #directives_sdl

Methods included from Mixins::HasDocumentation

#append_to_documentation, #derived_documentation, #documentation, #formatted_documentation

Methods included from Mixins::CanBeGraphQLOnly

#graphql_only, #graphql_only?

Methods included from Mixins::VerifiesGraphQLName

verify_name!

Constructor Details

#initialize(schema_def_state, name) ⇒ InterfaceType

Returns a new instance of InterfaceType.



38
39
40
41
42
43
44
45
# File 'lib/elastic_graph/schema_definition/schema_elements/interface_type.rb', line 38

def initialize(schema_def_state, name)
  field_factory = schema_def_state.factory.method(:new_field)
  schema_def_state.factory.new_type_with_subfields(:interface, name, wrapping_type: self, field_factory: field_factory) do |type|
    __skip__ = super(type) do
      yield self
    end
  end
end

Instance Method Details

#graphql_fields_by_nameObject

This contains more than just the proper interface fields; it also contains the fields from the subtypes, which winds up being used to generate an input filter and aggregation type.

For just the interface fields, use ‘interface_fields_by_name`.



53
54
55
56
57
# File 'lib/elastic_graph/schema_definition/schema_elements/interface_type.rb', line 53

def graphql_fields_by_name
  merged_fields_from_subtypes_by_name = super # delegates to the `HasSubtypes` definition.
  # The interface field definitions should take precedence over the merged fields from the subtypes.
  merged_fields_from_subtypes_by_name.merge(interface_fields_by_name)
end

#interface_fields_by_nameObject



60
61
62
# File 'lib/elastic_graph/schema_definition/schema_elements/interface_type.rb', line 60

def interface_fields_by_name
  __getobj__.graphql_fields_by_name
end