Class: GraphQL::Directive
- Inherits:
-
Object
- Object
- GraphQL::Directive
- Includes:
- GraphQL::Define::InstanceDefinable
- Defined in:
- lib/graphql/directive.rb
Overview
Directives are server-defined hooks for modifying execution.
Two directives are included out-of-the-box:
@skip(if: ...)
Skips the tagged field if the value ofif
is true@include(if: ...)
Includes the tagged field only ifif
is true
Constant Summary collapse
- LOCATIONS =
[ QUERY = :QUERY, MUTATION = :MUTATION, SUBSCRIPTION = :SUBSCRIPTION, FIELD = :FIELD, FRAGMENT_DEFINITION = :FRAGMENT_DEFINITION, FRAGMENT_SPREAD = :FRAGMENT_SPREAD, INLINE_FRAGMENT = :INLINE_FRAGMENT, SCHEMA = :SCHEMA, SCALAR = :SCALAR, OBJECT = :OBJECT, FIELD_DEFINITION = :FIELD_DEFINITION, ARGUMENT_DEFINITION = :ARGUMENT_DEFINITION, INTERFACE = :INTERFACE, UNION = :UNION, ENUM = :ENUM, ENUM_VALUE = :ENUM_VALUE, INPUT_OBJECT = :INPUT_OBJECT, INPUT_FIELD_DEFINITION = :INPUT_FIELD_DEFINITION, ]
- DEFAULT_DEPRECATION_REASON =
'No longer supported'
- LOCATION_DESCRIPTIONS =
{ QUERY: 'Location adjacent to a query operation.', MUTATION: 'Location adjacent to a mutation operation.', SUBSCRIPTION: 'Location adjacent to a subscription operation.', FIELD: 'Location adjacent to a field.', FRAGMENT_DEFINITION: 'Location adjacent to a fragment definition.', FRAGMENT_SPREAD: 'Location adjacent to a fragment spread.', INLINE_FRAGMENT: 'Location adjacent to an inline fragment.', SCHEMA: 'Location adjacent to a schema definition.', SCALAR: 'Location adjacent to a scalar definition.', OBJECT: 'Location adjacent to an object type definition.', FIELD_DEFINITION: 'Location adjacent to a field definition.', ARGUMENT_DEFINITION: 'Location adjacent to an argument definition.', INTERFACE: 'Location adjacent to an interface definition.', UNION: 'Location adjacent to a union definition.', ENUM: 'Location adjacent to an enum definition.', ENUM_VALUE: 'Location adjacent to an enum value definition.', INPUT_OBJECT: 'Location adjacent to an input object type definition.', INPUT_FIELD_DEFINITION: 'Location adjacent to an input object field definition.', }
- SkipDirective =
GraphQL::Directive.define do name "skip" description "Directs the executor to skip this field or fragment when the `if` argument is true." locations([GraphQL::Directive::FIELD, GraphQL::Directive::FRAGMENT_SPREAD, GraphQL::Directive::INLINE_FRAGMENT]) argument :if, !GraphQL::BOOLEAN_TYPE, 'Skipped when true.' end
- IncludeDirective =
GraphQL::Directive.define do name "include" description "Directs the executor to include this field or fragment only when the `if` argument is true." locations([GraphQL::Directive::FIELD, GraphQL::Directive::FRAGMENT_SPREAD, GraphQL::Directive::INLINE_FRAGMENT]) argument :if, !GraphQL::BOOLEAN_TYPE, 'Included when true.' end
- DeprecatedDirective =
GraphQL::Directive.define do name "deprecated" description "Marks an element of a GraphQL schema as no longer supported." locations([GraphQL::Directive::FIELD_DEFINITION, GraphQL::Directive::ENUM_VALUE]) reason_description = "Explains why this element was deprecated, usually also including a "\ "suggestion for how to access supported similar data. Formatted "\ "in [Markdown](https://daringfireball.net/projects/markdown/)." argument :reason, GraphQL::STRING_TYPE, reason_description, default_value: GraphQL::Directive::DEFAULT_DEPRECATION_REASON end
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#description ⇒ Object
Returns the value of attribute description.
-
#locations ⇒ Object
Returns the value of attribute locations.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize ⇒ Directive
constructor
A new instance of Directive.
- #on_field? ⇒ Boolean
- #on_fragment? ⇒ Boolean
- #on_operation? ⇒ Boolean
- #to_s ⇒ Object
Methods included from GraphQL::Define::InstanceDefinable
Constructor Details
#initialize ⇒ Directive
Returns a new instance of Directive.
58 59 60 |
# File 'lib/graphql/directive.rb', line 58 def initialize @arguments = {} end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
12 13 14 |
# File 'lib/graphql/directive.rb', line 12 def arguments @arguments end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/graphql/directive.rb', line 12 def description @description end |
#locations ⇒ Object
Returns the value of attribute locations.
12 13 14 |
# File 'lib/graphql/directive.rb', line 12 def locations @locations end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/graphql/directive.rb', line 12 def name @name end |
Instance Method Details
#on_field? ⇒ Boolean
66 67 68 |
# File 'lib/graphql/directive.rb', line 66 def on_field? locations.include?(FIELD) end |
#on_fragment? ⇒ Boolean
70 71 72 |
# File 'lib/graphql/directive.rb', line 70 def on_fragment? locations.include?(FRAGMENT_SPREAD) && locations.include?(INLINE_FRAGMENT) end |
#on_operation? ⇒ Boolean
74 75 76 |
# File 'lib/graphql/directive.rb', line 74 def on_operation? locations.include?(QUERY) && locations.include?(MUTATION) && locations.include?(SUBSCRIPTION) end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/graphql/directive.rb', line 62 def to_s "<GraphQL::Directive #{name}>" end |