Module: ElasticGraph::Apollo::SchemaDefinition::FieldExtension
- Includes:
- ApolloDirectives::Authenticated, ApolloDirectives::External, ApolloDirectives::Inaccessible, ApolloDirectives::Override, ApolloDirectives::Policy, ApolloDirectives::Provides, ApolloDirectives::Requires, ApolloDirectives::RequiresScopes, ApolloDirectives::Shareable, ApolloDirectives::Tag
- Defined in:
- elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/field_extension.rb
Overview
Extends SchemaDefinition::SchemaElements::Field to offer Apollo field directives.
Class Method Summary collapse
-
.tagged_with?(element, tag_name) ⇒ Boolean
Helper method that indicates if the given schema element has a specific tag.
Instance Method Summary collapse
-
#tag_with(tag_name) ⇒ void
Extension method designed to support Apollo’s contract variant tagging.
Methods included from ApolloDirectives::Tag
Methods included from ApolloDirectives::Shareable
Methods included from ApolloDirectives::RequiresScopes
Methods included from ApolloDirectives::Requires
Methods included from ApolloDirectives::Provides
Methods included from ApolloDirectives::Policy
Methods included from ApolloDirectives::Override
Methods included from ApolloDirectives::Inaccessible
Methods included from ApolloDirectives::External
Methods included from ApolloDirectives::Authenticated
Class Method Details
.tagged_with?(element, tag_name) ⇒ Boolean
Helper method that indicates if the given schema element has a specific tag.
70 71 72 |
# File 'elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/field_extension.rb', line 70 def self.tagged_with?(element, tag_name) element.directives.any? { |dir| dir.name == "tag" && dir.arguments == {name: tag_name} } end |
Instance Method Details
#tag_with(tag_name) ⇒ void
This method returns an undefined value.
Extension method designed to support Apollo’s contract variant tagging.
Calling this method on a field will cause the field and every schema element derived from the field (e.g. the filter field,
he aggregation field, etc), to be tagged with the given tag_name
, ensuring that all capabilities related to the field are
available in the contract variant.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/field_extension.rb', line 47 def tag_with(tag_name) on_each_generated_schema_element do |element| needs_tagging = if element.is_a?(ElasticGraph::SchemaDefinition::SchemaElements::SortOrderEnumValue) # Each sort order enum value is based on a full field path (e.g. `parentField_subField_furtherNestedField_ASC`). # We must only tag the enum if each part of the full field path is also tagged. In this example, we should only # tag the enum value if `parentField`, `subField`, and `furtherNestedField` are all tagged. element.sort_order_field_path.all? { |f| FieldExtension.tagged_with?(f, tag_name) } else true end if needs_tagging && !FieldExtension.tagged_with?(element, tag_name) (_ = element).apollo_tag name: tag_name end end end |