Module: GraphQL::Execution::DirectiveChecks

Defined in:
lib/graphql/execution/directive_checks.rb

Overview

Boolean checks for how an AST node’s directives should influence its execution

Constant Summary collapse

SKIP =
"skip"
INCLUDE =
"include"

Class Method Summary collapse

Class Method Details

.include?(directive_irep_nodes, query) ⇒ Boolean

Returns Should this node be included in the query?.

Returns:

  • (Boolean)

    Should this node be included in the query?



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/graphql/execution/directive_checks.rb', line 18

def include?(directive_irep_nodes, query)
  directive_irep_nodes.each do |directive_irep_node|
    name = directive_irep_node.name
    directive_defn = query.schema.directives[name]
    case name
    when SKIP
      args = query.arguments_for(directive_irep_node, directive_defn)
      if args['if'] == true
        return false
      end
    when INCLUDE
      args = query.arguments_for(directive_irep_node, directive_defn)
      if args['if'] == false
        return false
      end
    else
      # Undefined directive, or one we don't care about
    end
  end
  true
end

.skip?(ast_node, query) ⇒ Boolean

This covers ‘@include(if:)` & `@skip(if:)`

Returns:

  • (Boolean)

    Should this node be skipped altogether?



13
14
15
# File 'lib/graphql/execution/directive_checks.rb', line 13

def skip?(ast_node, query)
  !include?(ast_node, query)
end