Skip to content

Commit 1ee0a2f

Browse files
author
Nathaniel Woodthorpe
authored
Merge pull request #29 from d12/fix_immutable_node_errors_in_gql_19
Fix gem for graphql-ruby >= 1.9
2 parents 9a1a2b4 + bb17e93 commit 1ee0a2f

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
language: ruby
2+
# Work around an issue where bundler isn't installed correctly on Ruby 2.5.
3+
# We should remove this once Travis uses Ruby 2.6 by default.
4+
rvm: 2.6
25
script: bundle exec rspec

Gemfile.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
PATH
22
remote: .
33
specs:
4-
graphql-remote_loader (1.0.4)
5-
graphql (>= 1.6, < 1.9)
4+
graphql-remote_loader (1.0.5)
5+
graphql (~> 1.9)
66
graphql-batch (~> 0.3)
77

88
GEM
@@ -11,8 +11,8 @@ GEM
1111
byebug (10.0.2)
1212
coderay (1.1.2)
1313
diff-lcs (1.3)
14-
graphql (1.8.17)
15-
graphql-batch (0.4.0)
14+
graphql (1.9.12)
15+
graphql-batch (0.4.1)
1616
graphql (>= 1.3, < 2)
1717
promise.rb (~> 0.7.2)
1818
method_source (0.9.1)
@@ -42,11 +42,11 @@ PLATFORMS
4242
ruby
4343

4444
DEPENDENCIES
45-
bundler (~> 1.14)
45+
bundler (~> 2.0)
4646
graphql-remote_loader!
4747
pry-byebug (~> 3.4)
4848
rake (~> 10.0)
4949
rspec (~> 3.6)
5050

5151
BUNDLED WITH
52-
1.16.1
52+
2.0.2

graphql-remote_loader.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
2121
# spec.executables = [""]
2222
spec.require_paths = ["lib"]
2323

24-
spec.add_dependency "graphql", ">=1.6", "<1.9"
24+
spec.add_dependency "graphql", "~> 1.9"
2525
spec.add_dependency "graphql-batch", "~> 0.3"
2626

27-
spec.add_development_dependency "bundler", "~> 1.14"
27+
spec.add_development_dependency "bundler", "~> 2.0"
2828
spec.add_development_dependency "rake", "~> 10.0"
2929
spec.add_development_dependency "rspec", "~> 3.6"
3030
spec.add_development_dependency "pry-byebug", "~> 3.4"

lib/graphql/remote_loader/query_merger.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def merge_fragment_definitions(a_query, b_query)
4545
if matching_fragment_definition
4646
merge_query_recursive(a_definition, matching_fragment_definition)
4747
else
48-
b_query.definitions << a_definition
48+
# graphql-ruby Nodes aren't meant to be mutated, but I'd rather slightly abuse graphql-ruby vs
49+
# maintain my own Ruby data and parsing library implementing the GraphQL spec.
50+
b_query.instance_variable_set(:@definitions, [b_query.definitions, a_definition].flatten)
4951
end
5052
end
5153
end
@@ -79,7 +81,7 @@ def merge_query_recursive(a_query, b_query)
7981
matching_field.instance_variable_set(:@prime, new_prime)
8082
merge_query_recursive(a_query_selection, matching_field) unless exempt_node_types.any? { |type| matching_field.is_a?(type) }
8183
else
82-
b_query.selections << a_query_selection
84+
b_query.instance_variable_set(:@selections, [b_query.selections, a_query_selection].flatten)
8385
end
8486
end
8587
end
@@ -112,11 +114,11 @@ def apply_aliases!(query_selections)
112114
unless exempt_node_types.any? { |type| selection.is_a? type }
113115
prime_factor = selection.instance_variable_get(:@prime)
114116

115-
selection.alias = if selection.alias
117+
selection.instance_variable_set(:@alias, if selection.alias
116118
"p#{prime_factor}#{selection.alias}"
117119
else
118120
"p#{prime_factor}#{selection.name}"
119-
end
121+
end)
120122
end
121123

122124
# Some nodes don't have selections (e.g. fragment spreads)

lib/graphql/remote_loader/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module GraphQL
22
module RemoteLoader
3-
VERSION = "1.0.4"
3+
VERSION = "1.0.5"
44
end
55
end

0 commit comments

Comments
 (0)