Module: ElasticGraph::SchemaDefinition::Mixins::HasDirectives
- Included in:
- SchemaElements::Argument, SchemaElements::EnumType, SchemaElements::EnumValue, SchemaElements::Field, SchemaElements::ScalarType, SchemaElements::TypeWithSubfields, SchemaElements::UnionType
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_directives.rb
Overview
Provides support for annotating any schema element with a GraphQL directive.
Instance Method Summary collapse
-
#directive(name, arguments = {}) ⇒ void
Adds a GraphQL directive to the current schema element.
-
#directives ⇒ Array<SchemaElements::Directive>
Directives attached to this schema element.
-
#directives_sdl(suffix_with: "", prefix_with: "") ⇒ String
private
Helper method designed for use by including classes to get the formatted directive SDL.
Instance Method Details
#directive(name, arguments = {}) ⇒ void
If you’re using a custom directive rather than a standard GraphQL directive like @deprecated
, you’ll also need to use
API#raw_sdl to define the custom directive.
This method returns an undefined value.
Adds a GraphQL directive to the current schema element.
42 43 44 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_directives.rb', line 42 def directive(name, arguments = {}) directives << schema_def_state.factory.new_directive(name, arguments) end |
#directives ⇒ Array<SchemaElements::Directive>
Returns directives attached to this schema element.
59 60 61 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_directives.rb', line 59 def directives @directives ||= [] end |
#directives_sdl(suffix_with: "", prefix_with: "") ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Helper method designed for use by including classes to get the formatted directive SDL.
52 53 54 55 56 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_directives.rb', line 52 def directives_sdl(suffix_with: "", prefix_with: "") sdl = directives.map(&:to_sdl).join(" ") return sdl if sdl.empty? prefix_with + sdl + suffix_with end |