apiql 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apiql.gemspec +1 -1
- data/assets/javascripts/apiql.js +10 -10
- data/lib/apiql.rb +8 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23382bfe0c9946640a70754b0111d109267e24a00b23e675d16f2d5f5685938
|
4
|
+
data.tar.gz: d0fa0b8295cc1184b408e9817f7ba052b881abbefdab93533000af4d3fa1ea3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e795fba519ff01d1b7e21ed99f1e8f58619600249a5cd03b57b3b8acba407799c43fd2170dfb0d45d7b1ce6e18754caf23bd6c44ef28579dc571b2d644b52c17
|
7
|
+
data.tar.gz: a39ea52e53d9a8299fbaa0ae359ed25fa77112c0405279b1fa0cdbd089483d81894bf132466d197c32cee6c08415207a90c3d7763bec228258cfce9ff681db19
|
data/apiql.gemspec
CHANGED
data/assets/javascripts/apiql.js
CHANGED
@@ -2,7 +2,7 @@ const APIQL = {
|
|
2
2
|
on_error: null,
|
3
3
|
endpoint: '',
|
4
4
|
|
5
|
-
hash(s) {
|
5
|
+
hash: function(s) {
|
6
6
|
let hash = 0, i, chr
|
7
7
|
if(s.length === 0) return hash
|
8
8
|
for(i = 0; i < s.length; i++) {
|
@@ -13,33 +13,33 @@ const APIQL = {
|
|
13
13
|
return hash
|
14
14
|
},
|
15
15
|
|
16
|
-
call(schema, params) {
|
16
|
+
call: function(schema, params, form) {
|
17
17
|
if(!params) params = {}
|
18
18
|
if(!form) form = null
|
19
19
|
|
20
|
-
return new Promise((resolve, reject)
|
20
|
+
return new Promise(function(resolve, reject) {
|
21
21
|
if(params instanceof FormData) {
|
22
22
|
form = params
|
23
23
|
params = {}
|
24
24
|
}
|
25
25
|
|
26
26
|
if(form) {
|
27
|
-
Object.keys(params).forEach(key
|
27
|
+
Object.keys(params).forEach(function(key) {
|
28
28
|
form.append(key, params[key])
|
29
29
|
})
|
30
30
|
}
|
31
31
|
|
32
32
|
if(form) {
|
33
|
-
form.append('apiql',
|
33
|
+
form.append('apiql', APIQL.hash(schema))
|
34
34
|
} else {
|
35
|
-
params.apiql =
|
35
|
+
params.apiql = APIQL.hash(schema)
|
36
36
|
}
|
37
37
|
|
38
38
|
Vue.http.post(APIQL.endpoint, form || params)
|
39
|
-
.then(response
|
39
|
+
.then(function(response) {
|
40
40
|
resolve(response.body)
|
41
41
|
})
|
42
|
-
.catch(response
|
42
|
+
.catch(function(response) {
|
43
43
|
if(response.status == 401 && APIQL.on_error) {
|
44
44
|
APIQL.on_error(response)
|
45
45
|
return
|
@@ -54,10 +54,10 @@ const APIQL = {
|
|
54
54
|
}
|
55
55
|
|
56
56
|
Vue.http.post(APIQL.endpoint, form || params)
|
57
|
-
.then(response
|
57
|
+
.then(function(response) {
|
58
58
|
resolve(response.body)
|
59
59
|
})
|
60
|
-
.catch(response
|
60
|
+
.catch(function(response) {
|
61
61
|
if(APIQL.on_error) {
|
62
62
|
APIQL.on_error(response)
|
63
63
|
} else {
|
data/lib/apiql.rb
CHANGED
@@ -107,8 +107,8 @@ class APIQL
|
|
107
107
|
if request.present?
|
108
108
|
request = compile(request)
|
109
109
|
redis&.set("api-ql-cache-#{request_id}", request.to_json)
|
110
|
-
@@cache = {} if @@cache.count > 1000
|
111
110
|
@@cache[request_id] = request
|
111
|
+
@@cache = {} if(@@cache.count > 1000)
|
112
112
|
else
|
113
113
|
request = @@cache[request_id]
|
114
114
|
request ||= JSON.parse(redis.get("api-ql-cache-#{request_id}")) rescue nil
|
@@ -252,10 +252,10 @@ class APIQL
|
|
252
252
|
def render(schema)
|
253
253
|
result = {}
|
254
254
|
|
255
|
-
schema.
|
255
|
+
schema.each do |call|
|
256
256
|
if call.is_a? ::Hash
|
257
257
|
call.each do |function, sub_schema|
|
258
|
-
reg = function.match(/\A((?<alias>[\w
|
258
|
+
reg = function.match(/\A((?<alias>[\w\.\!]+):\s*)?(?<name>[\w\.\!]+)(\((?<params>.*?)\))?\z/)
|
259
259
|
raise Error, function unless reg.present?
|
260
260
|
|
261
261
|
name = reg[:alias] || reg[:name]
|
@@ -266,9 +266,9 @@ class APIQL
|
|
266
266
|
data = public_send(function, *params)
|
267
267
|
if @eager_load.present? && !data.is_a?(::Hash) && !data.is_a?(::Array)
|
268
268
|
if data.respond_to?(:eager_load)
|
269
|
-
data = data.
|
269
|
+
data = data.includes(eager_load)
|
270
270
|
elsif data.respond_to?(:id)
|
271
|
-
data = data.class.
|
271
|
+
data = data.class.includes(eager_load).find(data.id)
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
@@ -281,7 +281,7 @@ class APIQL
|
|
281
281
|
end
|
282
282
|
end
|
283
283
|
else
|
284
|
-
reg = call.match(/\A((?<alias>[\w
|
284
|
+
reg = call.match(/\A((?<alias>[\w\.\!]+):\s*)?(?<name>[\w\.\!]+)(\((?<params>.*?)\))?\z/)
|
285
285
|
raise Error, call unless reg.present?
|
286
286
|
|
287
287
|
name = reg[:alias] || reg[:name]
|
@@ -354,7 +354,7 @@ class APIQL
|
|
354
354
|
schema.each do |field|
|
355
355
|
if field.is_a? Hash
|
356
356
|
field.each do |field, sub_schema|
|
357
|
-
reg = field.match(/\A((?<alias>[\w
|
357
|
+
reg = field.match(/\A((?<alias>[\w\.\!]+):\s*)?(?<name>[\w\.\!]+)(\((?<params>.*?)\))?\z/)
|
358
358
|
raise Error, field unless reg.present?
|
359
359
|
|
360
360
|
name = reg[:alias] || reg[:name]
|
@@ -368,7 +368,7 @@ class APIQL
|
|
368
368
|
end
|
369
369
|
end
|
370
370
|
else
|
371
|
-
reg = field.match(/\A((?<alias>[\w
|
371
|
+
reg = field.match(/\A((?<alias>[\w\.\!]+):\s*)?(?<name>[\w\.\!]+)(\((?<params>.*?)\))?\z/)
|
372
372
|
raise Error, field unless reg.present?
|
373
373
|
|
374
374
|
name = reg[:alias] || reg[:name]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Silchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.7.
|
88
|
+
rubygems_version: 2.7.9
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: Implementation of the API language similar to GraphQL for Ruby on Rails
|