Module: ElasticGraph::SchemaDefinition::Mixins::HasDerivedGraphQLTypeCustomizations
- Included in:
- SchemaElements::EnumType, SchemaElements::ScalarType, SchemaElements::TypeWithSubfields, SchemaElements::UnionType
- Defined in:
- lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb
Overview
Mixin that supports the customization of derived GraphQL types.
For each type you define, ElasticGraph generates a number of derived GraphQL types that are needed to facilitate the ElasticGraph Query API. Methods in this module can be used to customize those derived GraphQL types.
Instance Method Summary collapse
-
#customize_derived_type_fields(type_name, *field_names, &customization_block) ⇒ void
Registers a customization block for the named fields on the named derived GraphQL type.
-
#customize_derived_types(*type_names, &customization_block) ⇒ void
Registers a customization block for the named derived graphql types.
- #derived_field_customizations_by_name_for_type(type) ⇒ Object
- #derived_field_customizations_by_type_and_field_name ⇒ Object
- #derived_type_customizations_by_name ⇒ Object
- #derived_type_customizations_for_type(type) ⇒ Object
Instance Method Details
#customize_derived_type_fields(type_name, *field_names, &customization_block) ⇒ void
This method returns an undefined value.
Registers a customization block for the named fields on the named derived GraphQL type. The provided block will get run on the named fields of the named derived GraphQL type, allowing them to be customized.
78 79 80 81 82 83 84 85 |
# File 'lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb', line 78 def customize_derived_type_fields(type_name, *field_names, &customization_block) customizations_by_field = derived_field_customizations_by_type_and_field_name[type_name] # : ::Hash[::String, ::Array[^(::ElasticGraph::SchemaDefinition::SchemaElements::Field) -> void]] field_names.each do |field_name| customizations = customizations_by_field[field_name] # : ::Array[^(::ElasticGraph::SchemaDefinition::SchemaElements::Field) -> void] customizations << customization_block end end |
#customize_derived_types(*type_names, &customization_block) ⇒ void
This method returns an undefined value.
Registers a customization block for the named derived graphql types. The provided block will get run on the named derived GraphQL types, allowing them to be customized.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb', line 48 def customize_derived_types(*type_names, &customization_block) if type_names.include?(:all) derived_type_customizations_for_all_types << customization_block else type_names.each do |t| derived_type_customizations = derived_type_customizations_by_name[t.to_s] # : ::Array[^(::ElasticGraph::SchemaDefinition::_Type) -> void] derived_type_customizations << customization_block end end end |
#derived_field_customizations_by_name_for_type(type) ⇒ Object
94 95 96 |
# File 'lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb', line 94 def derived_field_customizations_by_name_for_type(type) derived_field_customizations_by_type_and_field_name[type.name] # : ::Hash[::String, ::Array[^(SchemaElements::Field) -> void]] end |
#derived_field_customizations_by_type_and_field_name ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb', line 106 def derived_field_customizations_by_type_and_field_name @derived_field_customizations_by_type_and_field_name ||= ::Hash.new do |outer_hash, type| outer_hash[type] = ::Hash.new do |inner_hash, field_name| inner_hash[field_name] = [] end end end |
#derived_type_customizations_by_name ⇒ Object
99 100 101 102 103 |
# File 'lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb', line 99 def derived_type_customizations_by_name @derived_type_customizations_by_name ||= ::Hash.new do |hash, type_name| hash[type_name] = [] end end |
#derived_type_customizations_for_type(type) ⇒ Object
88 89 90 91 |
# File 'lib/elastic_graph/schema_definition/mixins/has_derived_graphql_type_customizations.rb', line 88 def derived_type_customizations_for_type(type) derived_type_customizations = derived_type_customizations_by_name[type.name] # : ::Array[^(::ElasticGraph::SchemaDefinition::_Type) -> void] derived_type_customizations + derived_type_customizations_for_all_types end |