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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2239e120580841a94f58c1a7e15a8be3b2563d352092817905975c69cb69dc26
4
- data.tar.gz: 3b22d1a1aab96520d240e6728d79754771098cec23b8275e0d63c1e06f4c2f7f
3
+ metadata.gz: f23382bfe0c9946640a70754b0111d109267e24a00b23e675d16f2d5f5685938
4
+ data.tar.gz: d0fa0b8295cc1184b408e9817f7ba052b881abbefdab93533000af4d3fa1ea3c
5
5
  SHA512:
6
- metadata.gz: '06876552a00283a6586b03c24730c6ef4a98065897d173170f721d67110e6439e17c7b94ed4ce491cde5be6cb8b559a61a7e07f5c216b13df87d05ad1ce4e7ba'
7
- data.tar.gz: 442ca29ae8e1f95132c964830ac36dafce8a433d9e5540efaf1fd044991c52d7514206bc4a79f69b5545abbe12a1786df4caec06bb90dc9288433b6e4bbe086c
6
+ metadata.gz: e795fba519ff01d1b7e21ed99f1e8f58619600249a5cd03b57b3b8acba407799c43fd2170dfb0d45d7b1ce6e18754caf23bd6c44ef28579dc571b2d644b52c17
7
+ data.tar.gz: a39ea52e53d9a8299fbaa0ae359ed25fa77112c0405279b1fa0cdbd089483d81894bf132466d197c32cee6c08415207a90c3d7763bec228258cfce9ff681db19
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'apiql'
7
- spec.version = '0.4.7'
7
+ spec.version = '0.4.8'
8
8
  spec.authors = ['Dmitry Silchenko']
9
9
  spec.email = ['dmitry@desofto.com']
10
10
 
@@ -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', this.hash(schema))
33
+ form.append('apiql', APIQL.hash(schema))
34
34
  } else {
35
- params.apiql = this.hash(schema)
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 {
@@ -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.map do |call|
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\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
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.eager_load(eager_load)
269
+ data = data.includes(eager_load)
270
270
  elsif data.respond_to?(:id)
271
- data = data.class.eager_load(eager_load).find(data.id)
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\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
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\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
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\.]+):\s*)?(?<name>[\w\.]+)(\((?<params>.*?)\))?\z/)
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.7
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-01-17 00:00:00.000000000 Z
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.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