graphql-remote_loader 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '08255df0d13cc9804c77ad8573250fcf28a324ba'
4
- data.tar.gz: b16f301f8bb77f5813ef6b96093d61cc583e9664
3
+ metadata.gz: b71151aac9fed6da47c53df2db83f4aa32178436
4
+ data.tar.gz: f556f9d29f9080efa8b326a7a21c443c090f2605
5
5
  SHA512:
6
- metadata.gz: 95baeb95ffc196efa52c8b47cadc8d0f81740719b4d51423ed9fc0ebf1d5afc4149309e01d3e66667baf854634116df6a19c24a626d781e3930cb15d032d7fce
7
- data.tar.gz: 161a3463f3b6337bf4ff437d60ef7ed8c022f0701c912351cd8c7f36fc653ec87bb2fc193bb631c198339e7a1759125af89056cd42c0e4329cbb3bf3648896df
6
+ metadata.gz: dbf5636dc0e6ab2976d763d4d66b30007b892acb608bc8846dc3731eebb87cd3932265843c2fad6470b0ba06ab9925fc42513b8f5a68ffb01b524693d41de320
7
+ data.tar.gz: d322e05826e6b70013d6ea692d1c05d47f645bd55cbef6e829e7678deff6eed87dc494320cbab5694d7a702a754c43ab03a8f580e35b67ddb9019b47b10038e9
data/Gemfile.lock CHANGED
@@ -1,42 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-remote_loader (1.0.2)
4
+ graphql-remote_loader (1.0.3)
5
5
  graphql (~> 1.6)
6
6
  graphql-batch (~> 0.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- byebug (9.1.0)
11
+ byebug (10.0.2)
12
12
  coderay (1.1.2)
13
13
  diff-lcs (1.3)
14
- graphql (1.8.4)
15
- graphql-batch (0.3.9)
14
+ graphql (1.8.11)
15
+ graphql-batch (0.3.10)
16
16
  graphql (>= 0.8, < 2)
17
17
  promise.rb (~> 0.7.2)
18
- method_source (0.9.0)
18
+ method_source (0.9.1)
19
19
  promise.rb (0.7.4)
20
- pry (0.11.3)
20
+ pry (0.12.0)
21
21
  coderay (~> 1.1.0)
22
22
  method_source (~> 0.9.0)
23
- pry-byebug (3.5.0)
24
- byebug (~> 9.1)
23
+ pry-byebug (3.6.0)
24
+ byebug (~> 10.0)
25
25
  pry (~> 0.10)
26
- rake (10.4.2)
27
- rspec (3.6.0)
28
- rspec-core (~> 3.6.0)
29
- rspec-expectations (~> 3.6.0)
30
- rspec-mocks (~> 3.6.0)
31
- rspec-core (3.6.0)
32
- rspec-support (~> 3.6.0)
33
- rspec-expectations (3.6.0)
26
+ rake (10.5.0)
27
+ rspec (3.8.0)
28
+ rspec-core (~> 3.8.0)
29
+ rspec-expectations (~> 3.8.0)
30
+ rspec-mocks (~> 3.8.0)
31
+ rspec-core (3.8.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-expectations (3.8.2)
34
34
  diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.6.0)
36
- rspec-mocks (3.6.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-mocks (3.8.0)
37
37
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.6.0)
39
- rspec-support (3.6.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-support (3.8.0)
40
40
 
41
41
  PLATFORMS
42
42
  ruby
@@ -11,7 +11,7 @@ module GraphQL
11
11
  # a) Avoid name collisions in the generated query
12
12
  # b) Determine which fields in the result JSON should be
13
13
  # handed fulfilled to each promise
14
- def self.load(query, context: {})
14
+ def self.load(query, context: {}, variables: {})
15
15
  @index ||= 1
16
16
  @index += 1
17
17
 
@@ -19,6 +19,8 @@ module GraphQL
19
19
 
20
20
  store_context(context)
21
21
 
22
+ interpolate_variables!(query, variables)
23
+
22
24
  self.for.load([query, prime, @context])
23
25
  end
24
26
 
@@ -68,7 +70,7 @@ module GraphQL
68
70
  private
69
71
 
70
72
  def perform(queries_and_primes)
71
- query_string = QueryMerger.merge(queries_and_primes)
73
+ query_string = QueryMerger.merge(queries_and_primes).gsub(/\s+/, " ")
72
74
  context = queries_and_primes[-1][-1]
73
75
  response = query(query_string, context: context).to_h
74
76
 
@@ -88,6 +90,33 @@ module GraphQL
88
90
  end
89
91
  end
90
92
 
93
+ # Interpolates variables into the given query.
94
+ # For String variables, surrounds the interpolated string in quotes.
95
+ # To interpolate a String as an Int, Float, or Bool, convert to the appropriate Ruby type.
96
+ #
97
+ # E.g.
98
+ # interpolate_variables("foo(bar: $my_var)", { my_var: "buzz" })
99
+ # => "foo(bar: \"buzz\")"
100
+ def self.interpolate_variables!(query, variables = {})
101
+ variables.each do |variable, value|
102
+ case value
103
+ when Integer, Float, TrueClass, FalseClass
104
+ # These types are safe to directly interpolate into the query, and GraphQL does not expect these types to be quoted.
105
+ query.gsub!("$#{variable.to_s}", value.to_s)
106
+ else
107
+ # A string is either a GraphQL String or ID type.
108
+ # This means we need to
109
+ # a) Surround the value in quotes
110
+ # b) escape special characters in the string
111
+ #
112
+ # This else also catches unknown objects, which could break the query if we directly interpolate.
113
+ # These objects get converted to strings, then escaped.
114
+
115
+ query.gsub!("$#{variable.to_s}", value.to_s.inspect)
116
+ end
117
+ end
118
+ end
119
+
91
120
  def dup(hash)
92
121
  JSON.parse(hash.to_json)
93
122
  end
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module RemoteLoader
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-remote_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Woodthorpe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-18 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql