Skip to content

Commit

Permalink
fix: Handle rails params in Any (#13)
Browse files Browse the repository at this point in the history
* Handle rails params in Any

* chore: test for rails strong parameters coercion
  • Loading branch information
lennyburdette authored and rylanc committed Aug 1, 2019
1 parent b7f19b9 commit 39e9213
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
42 changes: 42 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,44 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionpack (5.2.3)
actionview (= 5.2.3)
activesupport (= 5.2.3)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.3)
activesupport (= 5.2.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activesupport (5.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ast (2.4.0)
builder (3.2.3)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
diff-lcs (1.3)
erubi (1.8.0)
graphql (1.9.6)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.3)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
method_source (0.9.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
Expand All @@ -24,6 +55,13 @@ GEM
byebug (~> 11.0)
pry (~> 0.10)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rainbow (3.0.0)
rake (12.3.2)
rspec (3.8.0)
Expand All @@ -49,12 +87,16 @@ GEM
rubocop-rspec (1.33.0)
rubocop (>= 0.60.0)
ruby-progressbar (1.10.1)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.6.0)

PLATFORMS
ruby

DEPENDENCIES
actionpack
apollo-federation!
pry-byebug
rack
Expand Down
1 change: 1 addition & 0 deletions apollo-federation.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'graphql'

spec.add_development_dependency 'actionpack'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rack'
spec.add_development_dependency 'rake'
Expand Down
6 changes: 4 additions & 2 deletions lib/apollo-federation/any.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class Any < GraphQL::Schema::Scalar
def self.coerce_input(value, _ctx)
# TODO: Should we convert it to a Mash-like object?
result = {}
value.each_key do |key|
result[key.to_sym] = value[key]

# `value` can be an ActionController::Parameters instance
value.each_pair do |key, val|
result[key.to_sym] = val
end

result
Expand Down
10 changes: 10 additions & 0 deletions spec/apollo-federation/any_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

require 'spec_helper'
require 'apollo-federation/any'
require 'action_controller'

RSpec.describe ApolloFederation::Any do
it 'converts the keys to symbols' do
expect(
described_class.coerce_input({ 'one' => 1, 'two' => 2, '__typename' => 'Thing' }, nil),
).to eql(one: 1, two: 2, __typename: 'Thing')
end

it 'converts ActionController::Parameters' do
params = ActionController::Parameters.new(
'one' => 1, 'two' => 2, '__typename' => 'Thing',
)
expect(
described_class.coerce_input(params, nil),
).to eql(one: 1, two: 2, __typename: 'Thing')
end
end

0 comments on commit 39e9213

Please sign in to comment.