Sha256: 6fdc96a69779aa11562a4ba57cda14eedc61414b6f6cdb002646ca96fbdc2706

Contents?: true

Size: 1.32 KB

Versions: 51

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true
module GraphQL
  class Query
    class VariableValidationError < GraphQL::ExecutionError
      attr_accessor :value, :validation_result

      def initialize(variable_ast, type, value, validation_result)
        @value = value
        @validation_result = validation_result

        msg = "Variable $#{variable_ast.name} of type #{type.to_type_signature} was provided invalid value"

        if problem_fields.any?
          msg += " for #{problem_fields.join(", ")}"
        end

        super(msg)
        self.ast_node = variable_ast
      end

      def to_h
        # It is possible there are other extension items in this error, so handle
        # a one level deep merge explicitly. However beyond that only show the
        # latest value and problems.
        super.merge({ "extensions" => { "value" => value, "problems" => validation_result.problems }}) do |key, oldValue, newValue|
          if oldValue.respond_to?(:merge)
            oldValue.merge(newValue)
          else
            newValue
          end
        end
      end

      private

      def problem_fields
        @problem_fields ||= @validation_result
          .problems
          .reject { |problem| problem["path"].empty? }
          .map { |problem| "#{problem['path'].join('.')} (#{problem['explanation']})" }
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
graphql-1.12.25 lib/graphql/query/variable_validation_error.rb
graphql-2.0.12 lib/graphql/query/variable_validation_error.rb
graphql-1.13.15 lib/graphql/query/variable_validation_error.rb
graphql-2.0.11 lib/graphql/query/variable_validation_error.rb
graphql-1.13.14 lib/graphql/query/variable_validation_error.rb
graphql-1.13.13 lib/graphql/query/variable_validation_error.rb
graphql-2.0.9 lib/graphql/query/variable_validation_error.rb
graphql-2.0.8 lib/graphql/query/variable_validation_error.rb
graphql-2.0.7 lib/graphql/query/variable_validation_error.rb
graphql_cody-1.13.0 lib/graphql/query/variable_validation_error.rb
graphql-1.13.12 lib/graphql/query/variable_validation_error.rb
graphql-2.0.6 lib/graphql/query/variable_validation_error.rb
graphql-2.0.5 lib/graphql/query/variable_validation_error.rb
graphql-2.0.4 lib/graphql/query/variable_validation_error.rb
graphql-2.0.3 lib/graphql/query/variable_validation_error.rb
graphql-1.13.11 lib/graphql/query/variable_validation_error.rb
graphql-2.0.2 lib/graphql/query/variable_validation_error.rb
graphql-2.0.1 lib/graphql/query/variable_validation_error.rb
graphql-1.13.10 lib/graphql/query/variable_validation_error.rb
graphql-2.0.0 lib/graphql/query/variable_validation_error.rb