Class: GraphQL::Directive

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from GraphQL::Define::InstanceDefinable

included

Constructor Details

#initializeDirective

Returns a new instance of Directive.



18
19
20
# File 'lib/graphql/directive.rb', line 18

def initialize
  @arguments = {}
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



6
7
8
# File 'lib/graphql/directive.rb', line 6

def arguments
  @arguments
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/graphql/directive.rb', line 6

def description
  @description
end

#locationsObject

Returns the value of attribute locations.



6
7
8
# File 'lib/graphql/directive.rb', line 6

def locations
  @locations
end

#nameObject

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

Returns:

  • (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

Returns:

  • (Boolean)


34
35
36
# File 'lib/graphql/directive.rb', line 34

def on_field?
  locations.include?(FIELD)
end

#on_fragment?Boolean

Returns:

  • (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

Returns:

  • (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_sObject



30
31
32
# File 'lib/graphql/directive.rb', line 30

def to_s
  "<GraphQL::Directive #{name}>"
end