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 of if
is true
- @include(if: ...)
Includes the tagged field only if if
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, ]
- 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::Schema::Directive::Skip.graphql_definition
- IncludeDirective =
GraphQL::Schema::Directive::Include.graphql_definition
- DeprecatedDirective =
GraphQL::Schema::Directive::Deprecated.graphql_definition
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#arguments_class ⇒ Object
Returns the value of attribute arguments_class.
-
#ast_node ⇒ Object
Returns the value of attribute ast_node.
-
#default_directive ⇒ Object
writeonly
private
-
#description ⇒ Object
Returns the value of attribute description.
-
#locations ⇒ Object
Returns the value of attribute locations.
-
#name ⇒ Object
(also: #graphql_name)
Returns the value of attribute name.
Instance Method Summary collapse
-
#default_directive? ⇒ Boolean
Is this directive supplied by default? (eg
@skip
). -
#initialize ⇒ Directive
constructor
A new instance of Directive.
-
#inspect ⇒ Object
-
#on_field? ⇒ Boolean
-
#on_fragment? ⇒ Boolean
-
#on_operation? ⇒ Boolean
-
#to_s ⇒ Object
-
#type_class ⇒ Object
Methods included from GraphQL::Define::InstanceDefinable
#define, #initialize_copy, #metadata, #redefine
Constructor Details
#initialize ⇒ Directive
Returns a new instance of Directive.
69 70 71 72 |
# File 'lib/graphql/directive.rb', line 69 def initialize @arguments = {} @default_directive = false end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
13 14 15 |
# File 'lib/graphql/directive.rb', line 13 def arguments @arguments end |
#arguments_class ⇒ Object
Returns the value of attribute arguments_class.
13 14 15 |
# File 'lib/graphql/directive.rb', line 13 def arguments_class @arguments_class end |
#ast_node ⇒ Object
Returns the value of attribute ast_node.
14 15 16 |
# File 'lib/graphql/directive.rb', line 14 def ast_node @ast_node end |
#default_directive=(value) ⇒ Object (writeonly)
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.
16 17 18 |
# File 'lib/graphql/directive.rb', line 16 def default_directive=(value) @default_directive = value end |
#description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/graphql/directive.rb', line 13 def description @description end |
#locations ⇒ Object
Returns the value of attribute locations.
13 14 15 |
# File 'lib/graphql/directive.rb', line 13 def locations @locations end |
#name ⇒ Object Also known as: graphql_name
Returns the value of attribute name.
13 14 15 |
# File 'lib/graphql/directive.rb', line 13 def name @name end |
Instance Method Details
#default_directive? ⇒ Boolean
Returns Is this directive supplied by default? (eg @skip
).
91 92 93 |
# File 'lib/graphql/directive.rb', line 91 def default_directive? @default_directive end |
#inspect ⇒ Object
95 96 97 |
# File 'lib/graphql/directive.rb', line 95 def inspect "#<GraphQL::Directive #{name}>" end |
#on_field? ⇒ Boolean
78 79 80 |
# File 'lib/graphql/directive.rb', line 78 def on_field? locations.include?(FIELD) end |
#on_fragment? ⇒ Boolean
82 83 84 |
# File 'lib/graphql/directive.rb', line 82 def on_fragment? locations.include?(FRAGMENT_SPREAD) && locations.include?(INLINE_FRAGMENT) end |
#on_operation? ⇒ Boolean
86 87 88 |
# File 'lib/graphql/directive.rb', line 86 def on_operation? locations.include?(QUERY) && locations.include?(MUTATION) && locations.include?(SUBSCRIPTION) end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/graphql/directive.rb', line 74 def to_s "<GraphQL::Directive #{name}>" end |
#type_class ⇒ Object
99 100 101 |
# File 'lib/graphql/directive.rb', line 99 def type_class [:type_class] end |