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:
- lib/elastic_graph/apollo/schema_definition/field_extension.rb
Overview
Extension module applied to ‘ElasticGraph::SchemaDefinition::SchemaElements::Field` to add Apollo tagging support.
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) ⇒ Object
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.
53 54 55 |
# File 'lib/elastic_graph/apollo/schema_definition/field_extension.rb', line 53 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) ⇒ Object
Extension method designed to support Apollo’s contract variant tagging:
www.apollographql.com/docs/studio/contracts/
Calling this method on a field will cause the field to be tagged and also every schema element derived from the field (e.g. the filter field, the aggregation field, an the sort order enum), ensuring that all capabilities related to the field are available in the contract variant.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elastic_graph/apollo/schema_definition/field_extension.rb', line 34 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 |