Class: GraphQL::Directive
- Inherits:
-
Object
- Object
- GraphQL::Directive
- Includes:
- GraphQL::Define::InstanceDefinable
- Defined in:
- lib/graphql/directive.rb
Constant Summary collapse
- LOCATIONS =
[ QUERY = :QUERY, MUTATION = :MUTATION, SUBSCRIPTION = :SUBSCRIPTION, FIELD = :FIELD, FRAGMENT_DEFINITION = :FRAGMENT_DEFINITION, FRAGMENT_SPREAD = :FRAGMENT_SPREAD, INLINE_FRAGMENT = :INLINE_FRAGMENT, ]
- SkipDirective =
GraphQL::Directive.define do name "skip" description "Ignore this part of the query if `if` is true" locations([GraphQL::Directive::FIELD, GraphQL::Directive::FRAGMENT_SPREAD, GraphQL::Directive::INLINE_FRAGMENT]) argument :if, !GraphQL::BOOLEAN_TYPE include_proc -> (arguments) { !arguments["if"] } end
- IncludeDirective =
GraphQL::Directive.define do name "include" description "Include this part of the query if `if` is true" locations([GraphQL::Directive::FIELD, GraphQL::Directive::FRAGMENT_SPREAD, GraphQL::Directive::INLINE_FRAGMENT]) argument :if, !GraphQL::BOOLEAN_TYPE include_proc -> (arguments) { arguments["if"] } 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
- #include?(arguments) ⇒ Boolean
- #include_proc=(include_proc) ⇒ Object
-
#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.
18 19 20 |
# File 'lib/graphql/directive.rb', line 18 def initialize @arguments = {} end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
6 7 8 |
# File 'lib/graphql/directive.rb', line 6 def arguments @arguments end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/graphql/directive.rb', line 6 def description @description end |
#locations ⇒ Object
Returns the value of attribute locations.
6 7 8 |
# File 'lib/graphql/directive.rb', line 6 def locations @locations end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/graphql/directive.rb', line 6 def name @name end |
Instance Method Details
#include?(arguments) ⇒ Boolean
22 23 24 |
# File 'lib/graphql/directive.rb', line 22 def include?(arguments) @include_proc.call(arguments) end |
#include_proc=(include_proc) ⇒ Object
26 27 28 |
# File 'lib/graphql/directive.rb', line 26 def include_proc=(include_proc) @include_proc = include_proc end |
#on_field? ⇒ Boolean
34 35 36 |
# File 'lib/graphql/directive.rb', line 34 def on_field? locations.include?(FIELD) end |
#on_fragment? ⇒ Boolean
38 39 40 |
# File 'lib/graphql/directive.rb', line 38 def on_fragment? locations.include?(FRAGMENT_SPREAD) && locations.include?(INLINE_FRAGMENT) end |
#on_operation? ⇒ Boolean
42 43 44 |
# File 'lib/graphql/directive.rb', line 42 def on_operation? locations.include?(QUERY) && locations.include?(MUTATION) && locations.include?(SUBSCRIPTION) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/graphql/directive.rb', line 30 def to_s "<GraphQL::Directive #{name}>" end |