Skip to content

Commit

Permalink
Merge pull request #817 from phyrog/master
Browse files Browse the repository at this point in the history
Fix bug concerning `as` and `prepare` on arguments
  • Loading branch information
Robert Mosolgo committed Jun 29, 2017
2 parents 9ce958f + ad2d2af commit 2db36e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/graphql/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ def self.from_dsl(name, type = nil, description = nil, default_value: NO_DEFAULT
if default_value != NO_DEFAULT_VALUE
argument.default_value = default_value
end
argument.as = as
argument.prepare = prepare

as && argument.as = as
if prepare != DefaultPrepare
argument.prepare = prepare
end

argument
end
Expand Down
17 changes: 17 additions & 0 deletions spec/graphql/argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
arg_3 = arg_2.redefine { as :ff }
assert_equal arg_3.expose_as, "ff"
end

it "can be set in the passed block" do
argument = GraphQL::Argument.define do
name "arg"
as "arg_name"
end
assert_equal "arg_name", argument.as
end
end

describe "prepare" do
Expand All @@ -69,5 +77,14 @@
argument = GraphQL::Argument.define(name: :someNumber, type: GraphQL::INT_TYPE)
assert_equal argument.prepare(1, nil), 1
end

it "can be set in the passed block" do
prepare_proc = Proc.new { |arg, ctx| arg + ctx[:val] }
argument = GraphQL::Argument.define do
name "arg"
prepare prepare_proc
end
assert_equal argument.prepare(1, {val: 1}), 2
end
end
end

0 comments on commit 2db36e7

Please sign in to comment.