Sha256: 18d5ba8368a027a2f5ceb172834baeee1f7ad28c7ececa60fe8067869dd96c79

Contents?: true

Size: 1.24 KB

Versions: 32

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    module RequiredArgumentsArePresent
      def on_field(node, _parent)
        assert_required_args(node, field_definition)
        super
      end

      def on_directive(node, _parent)
        directive_defn = context.schema.directives[node.name]
        assert_required_args(node, directive_defn)
        super
      end

      private

      def assert_required_args(ast_node, defn)
        present_argument_names = ast_node.arguments.map(&:name)
        required_argument_names = defn.arguments.each_value
          .select { |a| a.type.kind.non_null? && !a.default_value? && context.warden.get_argument(defn, a.name) }
          .map(&:name)

        missing_names = required_argument_names - present_argument_names
        if missing_names.any?
          add_error(GraphQL::StaticValidation::RequiredArgumentsArePresentError.new(
            "#{ast_node.class.name.split("::").last} '#{ast_node.name}' is missing required arguments: #{missing_names.join(", ")}",
            nodes: ast_node,
            class_name: ast_node.class.name.split("::").last,
            name: ast_node.name,
            arguments: "#{missing_names.join(", ")}"
          ))
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
graphql-1.12.21 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.20 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.19 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.11.10 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.18 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.11.9 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.17 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.16 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.15 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.14 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.13 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.12 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.11 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.10 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.9 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.8 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.7 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.6 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.12.5 lib/graphql/static_validation/rules/required_arguments_are_present.rb
graphql-1.11.8 lib/graphql/static_validation/rules/required_arguments_are_present.rb