Skip to content

Commit b2e3c8b

Browse files
committed
Create no-op DefaultPrepare module
1 parent 6b21a92 commit b2e3c8b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/graphql/argument.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class Argument
4040

4141
ensure_defined(:name, :description, :default_value, :type=, :type, :as, :expose_as, :prepare)
4242

43+
# @api private
44+
module DefaultPrepare
45+
def self.call(value); value; end
46+
end
47+
48+
def initialize
49+
@prepare_proc = DefaultPrepare
50+
end
51+
4352
def initialize_copy(other)
4453
@expose_as = nil
4554
end
@@ -75,7 +84,6 @@ def expose_as
7584
# @param value
7685
# @return [Object] The prepared `value` for this argument or `value` itself if no `prepare` function exists.
7786
def prepare(value)
78-
return value unless @prepare_proc.respond_to?(:call)
7987
@prepare_proc.call(value)
8088
end
8189

@@ -87,7 +95,7 @@ def prepare=(prepare_proc)
8795

8896
NO_DEFAULT_VALUE = Object.new
8997
# @api private
90-
def self.from_dsl(name, type = nil, description = nil, default_value: NO_DEFAULT_VALUE, as: nil, prepare: nil, &block)
98+
def self.from_dsl(name, type = nil, description = nil, default_value: NO_DEFAULT_VALUE, as: nil, prepare: DefaultPrepare, &block)
9199
argument = if block_given?
92100
GraphQL::Argument.define(&block)
93101
else

0 commit comments

Comments
 (0)