Sha256: f3e32278cc3ff866ec350e4d33557282c0f3d90f8f71a81a71ac103c50095cc3

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

module GraphQL
  module Execution
    # Boolean checks for how an AST node's directives should
    # influence its execution
    module DirectiveChecks
      SKIP = "skip"
      INCLUDE = "include"

      module_function

      # This covers `@include(if:)` & `@skip(if:)`
      # @return [Boolean] Should this node be skipped altogether?
      def skip?(ast_node, query)
        !include?(ast_node, query)
      end

      # @return [Boolean] Should this node be included in the query?
      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
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-1.0.0 lib/graphql/execution/directive_checks.rb
graphql-0.19.4 lib/graphql/execution/directive_checks.rb
graphql-0.19.3 lib/graphql/execution/directive_checks.rb
graphql-0.19.2 lib/graphql/execution/directive_checks.rb
graphql-0.19.1 lib/graphql/execution/directive_checks.rb
graphql-0.19.0 lib/graphql/execution/directive_checks.rb
graphql-0.18.15 lib/graphql/execution/directive_checks.rb