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 =

:nodoc:

"skip"
INCLUDE =
"include"

Class Method Summary collapse

Class Method Details

.include?(directive_ast_nodes, query) ⇒ Boolean

Returns

  • Boolean — Should this node be included in the query?

:call-seq:

include?(directive_ast_nodes, query) -> bool

: (Array directive_ast_nodes, GraphQL::Query query) -> bool

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/graphql/execution/directive_checks.rb', line 21

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