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 +4 -4
- data/Gemfile.lock +20 -20
- data/lib/graphql/remote_loader/loader.rb +31 -2
- data/lib/graphql/remote_loader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b71151aac9fed6da47c53df2db83f4aa32178436
|
4
|
+
data.tar.gz: f556f9d29f9080efa8b326a7a21c443c090f2605
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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 (
|
11
|
+
byebug (10.0.2)
|
12
12
|
coderay (1.1.2)
|
13
13
|
diff-lcs (1.3)
|
14
|
-
graphql (1.8.
|
15
|
-
graphql-batch (0.3.
|
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.
|
18
|
+
method_source (0.9.1)
|
19
19
|
promise.rb (0.7.4)
|
20
|
-
pry (0.
|
20
|
+
pry (0.12.0)
|
21
21
|
coderay (~> 1.1.0)
|
22
22
|
method_source (~> 0.9.0)
|
23
|
-
pry-byebug (3.
|
24
|
-
byebug (~>
|
23
|
+
pry-byebug (3.6.0)
|
24
|
+
byebug (~> 10.0)
|
25
25
|
pry (~> 0.10)
|
26
|
-
rake (10.
|
27
|
-
rspec (3.
|
28
|
-
rspec-core (~> 3.
|
29
|
-
rspec-expectations (~> 3.
|
30
|
-
rspec-mocks (~> 3.
|
31
|
-
rspec-core (3.
|
32
|
-
rspec-support (~> 3.
|
33
|
-
rspec-expectations (3.
|
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.
|
36
|
-
rspec-mocks (3.
|
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.
|
39
|
-
rspec-support (3.
|
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
|
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.
|
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-
|
11
|
+
date: 2018-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|