graphqljs-rails 0.4.5 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/graphql.js +48 -34
- data/app/assets/javascripts/graphql.min.js +1 -1
- data/lib/graphqljs/rails/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: da6112980029f67b3195ab3ac18e92bd35ae6cd6
|
|
4
|
+
data.tar.gz: c96b77197aa7d03026ba246e324c50d6d2cda0db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f2b0745e374f69b250a6adadc02abcdd101966b0773746ecdb0460c2ab2ce827b44833102cd439181f41b6c950b0d45a989c761bf2036219882fad9688f0dbd9
|
|
7
|
+
data.tar.gz: faf374c81a33ec4205b87e6a0098e964182703f046c8d792c551886e325e9b98763d649df1420e0c2d2237f522a20641a7ae6bb6c5ccbb7e2c41dd1184f09b09
|
|
@@ -16,21 +16,31 @@
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
for (; i < length; i++) {
|
|
21
21
|
var obj = arguments[i]
|
|
22
22
|
merge(obj)
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
return extended
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
27
|
+
|
|
28
|
+
function __unique(array) {
|
|
29
|
+
return array.filter( function onlyUnique(value, index, self) {
|
|
30
|
+
return self.indexOf(value) === index;
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function __request(method, url, headers, data, asJson, callback) {
|
|
35
|
+
if (asJson) {
|
|
36
|
+
var body = JSON.stringify({query: data.query, variables: data.variables});
|
|
37
|
+
} else {
|
|
38
|
+
var body = "query=" + encodeURIComponent(data.query) + "&variables=" + encodeURIComponent(JSON.stringify(data.variables))
|
|
39
|
+
}
|
|
30
40
|
if (typeof XMLHttpRequest != 'undefined') {
|
|
31
41
|
var xhr = new XMLHttpRequest
|
|
32
42
|
xhr.open(method, url, true)
|
|
33
|
-
xhr.setRequestHeader('Content-
|
|
43
|
+
xhr.setRequestHeader('Content-Type', (asJson ? 'application/json' : 'application/x-www-form-urlencoded'))
|
|
34
44
|
xhr.setRequestHeader('Accept', 'application/json')
|
|
35
45
|
for (var key in headers) { xhr.setRequestHeader(key, headers[key]) }
|
|
36
46
|
xhr.onerror = function () { callback(xhr, xhr.status) }
|
|
@@ -45,7 +55,7 @@
|
|
|
45
55
|
path: uri.path,
|
|
46
56
|
method: "POST",
|
|
47
57
|
headers: __extend({
|
|
48
|
-
'Content-type': 'application/x-www-form-urlencoded',
|
|
58
|
+
'Content-type': (asJson ? 'application/json' : 'application/x-www-form-urlencoded'),
|
|
49
59
|
'Accept': 'application/json'
|
|
50
60
|
}, headers)
|
|
51
61
|
}, function (response) {
|
|
@@ -60,11 +70,11 @@
|
|
|
60
70
|
req.end()
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
|
-
|
|
73
|
+
|
|
64
74
|
function __isTagCall(strings) {
|
|
65
75
|
return Object.prototype.toString.call(strings) == '[object Array]' && strings.raw
|
|
66
76
|
}
|
|
67
|
-
|
|
77
|
+
|
|
68
78
|
function GraphQLClient(url, options) {
|
|
69
79
|
if (!(this instanceof GraphQLClient)) {
|
|
70
80
|
var client = new GraphQLClient(url, options, true)
|
|
@@ -82,24 +92,24 @@
|
|
|
82
92
|
}
|
|
83
93
|
if (!options)
|
|
84
94
|
options = {}
|
|
85
|
-
|
|
95
|
+
|
|
86
96
|
if (!options.fragments)
|
|
87
97
|
options.fragments = {}
|
|
88
|
-
|
|
89
|
-
this.options = options
|
|
98
|
+
|
|
99
|
+
this.options = options || {}
|
|
90
100
|
this._fragments = this.buildFragments(options.fragments)
|
|
91
101
|
this._sender = this.createSenderFunction(url)
|
|
92
102
|
this.createHelpers(this._sender)
|
|
93
103
|
}
|
|
94
|
-
|
|
104
|
+
|
|
95
105
|
// "fragment auth.login" will be "fragment auth_login"
|
|
96
106
|
FRAGMENT_SEPERATOR = "_"
|
|
97
|
-
|
|
107
|
+
|
|
98
108
|
// The autodeclare keyword.
|
|
99
109
|
GraphQLClient.AUTODECLARE_PATTERN = /\(@autodeclare\)|\(@autotype\)/
|
|
100
|
-
|
|
110
|
+
|
|
101
111
|
GraphQLClient.FRAGMENT_PATTERN = /\.\.\.\s*([A-Za-z0-9\.\_]+)/g
|
|
102
|
-
|
|
112
|
+
|
|
103
113
|
// Flattens nested object
|
|
104
114
|
/*
|
|
105
115
|
* {a: {b: {c: 1, d: 2}}} => {"a.b.c": 1, "a.b.d": 2}
|
|
@@ -115,7 +125,7 @@
|
|
|
115
125
|
}
|
|
116
126
|
return out
|
|
117
127
|
}
|
|
118
|
-
|
|
128
|
+
|
|
119
129
|
// Gets path from object
|
|
120
130
|
/*
|
|
121
131
|
* {a: {b: {c: 1, d: 2}}}, "a.b.c" => 1
|
|
@@ -128,7 +138,7 @@
|
|
|
128
138
|
}
|
|
129
139
|
return obj
|
|
130
140
|
}
|
|
131
|
-
|
|
141
|
+
|
|
132
142
|
GraphQLClient.prototype.collectFragments = function (query, fragments) {
|
|
133
143
|
var that = this
|
|
134
144
|
var fragmentRegexp = GraphQLClient.FRAGMENT_PATTERN
|
|
@@ -153,9 +163,9 @@
|
|
|
153
163
|
}
|
|
154
164
|
}
|
|
155
165
|
})
|
|
156
|
-
return collectedFragments
|
|
166
|
+
return __unique(collectedFragments)
|
|
157
167
|
}
|
|
158
|
-
|
|
168
|
+
|
|
159
169
|
GraphQLClient.prototype.processQuery = function (query, fragments) {
|
|
160
170
|
var fragmentRegexp = GraphQLClient.FRAGMENT_PATTERN
|
|
161
171
|
var collectedFragments = this.collectFragments(query, fragments)
|
|
@@ -167,7 +177,7 @@
|
|
|
167
177
|
return !query.match(fragment)
|
|
168
178
|
})).join("\n")
|
|
169
179
|
}
|
|
170
|
-
|
|
180
|
+
|
|
171
181
|
GraphQLClient.prototype.autoDeclare = function (query, variables) {
|
|
172
182
|
var typeMap = {
|
|
173
183
|
string: "String",
|
|
@@ -188,7 +198,7 @@
|
|
|
188
198
|
return types ? "("+ types +")" : ""
|
|
189
199
|
})
|
|
190
200
|
}
|
|
191
|
-
|
|
201
|
+
|
|
192
202
|
GraphQLClient.prototype.cleanAutoDeclareAnnotations = function (variables) {
|
|
193
203
|
if (!variables) variables = {}
|
|
194
204
|
var newVariables = {}
|
|
@@ -199,7 +209,7 @@
|
|
|
199
209
|
}
|
|
200
210
|
return newVariables
|
|
201
211
|
}
|
|
202
|
-
|
|
212
|
+
|
|
203
213
|
GraphQLClient.prototype.buildFragments = function (fragments) {
|
|
204
214
|
var that = this
|
|
205
215
|
fragments = this.flatten(fragments || {})
|
|
@@ -214,11 +224,11 @@
|
|
|
214
224
|
}
|
|
215
225
|
return fragmentObject
|
|
216
226
|
}
|
|
217
|
-
|
|
227
|
+
|
|
218
228
|
GraphQLClient.prototype.buildQuery = function (query, variables) {
|
|
219
229
|
return this.autoDeclare(this.processQuery(query, this._fragments, variables), variables)
|
|
220
230
|
}
|
|
221
|
-
|
|
231
|
+
|
|
222
232
|
GraphQLClient.prototype.createSenderFunction = function (url) {
|
|
223
233
|
var that = this
|
|
224
234
|
return function (query) {
|
|
@@ -230,12 +240,12 @@
|
|
|
230
240
|
if (!variables) variables = {}
|
|
231
241
|
var fragmentedQuery = that.buildQuery(query, variables)
|
|
232
242
|
headers = __extend((that.options.headers||{}), (requestOptions.headers||{}))
|
|
233
|
-
|
|
243
|
+
|
|
234
244
|
return new Promise(function (resolve, reject) {
|
|
235
245
|
__request(that.options.method || "post", url, headers, {
|
|
236
246
|
query: fragmentedQuery,
|
|
237
247
|
variables: that.cleanAutoDeclareAnnotations(variables)
|
|
238
|
-
}, function (response, status) {
|
|
248
|
+
}, !!that.options.asJSON, function (response, status) {
|
|
239
249
|
if (status == 200) {
|
|
240
250
|
if (response.errors) {
|
|
241
251
|
reject(response.errors)
|
|
@@ -254,7 +264,7 @@
|
|
|
254
264
|
return caller
|
|
255
265
|
}
|
|
256
266
|
}
|
|
257
|
-
|
|
267
|
+
|
|
258
268
|
GraphQLClient.prototype.createHelpers = function (sender) {
|
|
259
269
|
var that = this
|
|
260
270
|
function helper(query) {
|
|
@@ -295,15 +305,19 @@
|
|
|
295
305
|
return sender(query, {})
|
|
296
306
|
}
|
|
297
307
|
}
|
|
298
|
-
|
|
308
|
+
|
|
299
309
|
GraphQLClient.prototype.fragments = function () {
|
|
300
310
|
return this._fragments
|
|
301
311
|
}
|
|
302
|
-
|
|
312
|
+
|
|
303
313
|
GraphQLClient.prototype.getOptions = function () {
|
|
304
|
-
return this.options
|
|
314
|
+
return this.options || {}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
GraphQLClient.prototype.headers = function (newHeaders) {
|
|
318
|
+
return this.options.headers = __extend(this.options.headers, newHeaders)
|
|
305
319
|
}
|
|
306
|
-
|
|
320
|
+
|
|
307
321
|
GraphQLClient.prototype.fragment = function (fragment) {
|
|
308
322
|
if (typeof fragment == 'string') {
|
|
309
323
|
var _fragment = this._fragments[fragment.replace(/\./g, FRAGMENT_SEPERATOR)]
|
|
@@ -317,7 +331,7 @@
|
|
|
317
331
|
return this._fragments
|
|
318
332
|
}
|
|
319
333
|
}
|
|
320
|
-
|
|
334
|
+
|
|
321
335
|
GraphQLClient.prototype.ql = function (strings) {
|
|
322
336
|
var that = this
|
|
323
337
|
fragments = Array.prototype.slice.call(arguments, 1)
|
|
@@ -333,7 +347,7 @@
|
|
|
333
347
|
query = ((this.__prefix||"") + " " + query + " " + (this.__suffix||"")).trim()
|
|
334
348
|
return query
|
|
335
349
|
}
|
|
336
|
-
|
|
350
|
+
|
|
337
351
|
;(function (root, factory) {
|
|
338
352
|
if (typeof define === 'function' && define.amd) {
|
|
339
353
|
define(function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){function a(){var b={},c=!1,d=0,e=arguments.length;"[object Boolean]"==Object.prototype.toString.call(arguments[0])&&(c=arguments[0],d++);for(var f=function(d){for(var e in d)Object.prototype.hasOwnProperty.call(d,e)&&(c&&"[object Object]"==Object.prototype.toString.call(d[e])?b[e]=a(!0,b[e],d[e]):b[e]=d[e])};e>d;d++){var g=arguments[d];f(g)}return b}function b(b,c,d,e,f){var
|
|
1
|
+
!function(){function a(){var b={},c=!1,d=0,e=arguments.length;"[object Boolean]"==Object.prototype.toString.call(arguments[0])&&(c=arguments[0],d++);for(var f=function(d){for(var e in d)Object.prototype.hasOwnProperty.call(d,e)&&(c&&"[object Object]"==Object.prototype.toString.call(d[e])?b[e]=a(!0,b[e],d[e]):b[e]=d[e])};e>d;d++){var g=arguments[d];f(g)}return b}function b(a){return a.filter(function(a,b,c){return c.indexOf(a)===b})}function c(b,c,d,e,f,g){if(f)var h=JSON.stringify({query:e.query,variables:e.variables});else var h="query="+encodeURIComponent(e.query)+"&variables="+encodeURIComponent(JSON.stringify(e.variables));if("undefined"!=typeof XMLHttpRequest){var i=new XMLHttpRequest;i.open(b,c,!0),i.setRequestHeader("Content-Type",f?"application/json":"application/x-www-form-urlencoded"),i.setRequestHeader("Accept","application/json");for(var j in d)i.setRequestHeader(j,d[j]);i.onerror=function(){g(i,i.status)},i.onload=function(){g(JSON.parse(i.responseText),i.status)},i.send(h)}else if("function"==typeof require){var k=require("http"),l=require("url"),m=l.parse(c),n=k.request({protocol:m.protocol,hostname:m.hostname,port:m.port,path:m.path,method:"POST",headers:a({"Content-type":f?"application/json":"application/x-www-form-urlencoded",Accept:"application/json"},d)},function(a){var b="";a.setEncoding("utf8"),a.on("data",function(a){b+=a}),a.on("end",function(){g(JSON.parse(b),a.statusCode)})});n.write(h),n.end()}}function d(a){return"[object Array]"==Object.prototype.toString.call(a)&&a.raw}function e(a,b){if(!(this instanceof e)){var c=new e(a,b,!0),d=c._sender;for(var f in c)"function"==typeof c[f]&&(d[f]=c[f].bind(c),c[f].declare&&(d[f].declare=c[f].declare.bind(c)),c[f].run&&(d[f].run=c[f].run.bind(c)));return d}if(arguments[2]!==!0)throw new Error("You cannot create GraphQLClient instance. Please call GraphQLClient as function.");b||(b={}),b.fragments||(b.fragments={}),this.options=b||{},this._fragments=this.buildFragments(b.fragments),this._sender=this.createSenderFunction(a),this.createHelpers(this._sender)}FRAGMENT_SEPERATOR="_",e.AUTODECLARE_PATTERN=/\(@autodeclare\)|\(@autotype\)/,e.FRAGMENT_PATTERN=/\.\.\.\s*([A-Za-z0-9\.\_]+)/g,e.prototype.flatten=function(a){var b,c=arguments[1]||"",d=arguments[2]||{};for(b in a)a.hasOwnProperty(b)&&("object"==typeof a[b]?this.flatten(a[b],c+b+FRAGMENT_SEPERATOR,d):d[c+b]=a[b]);return d},e.prototype.fragmentPath=function(a,b){var c=new Function("fragments","return fragments."+b.replace(/\./g,FRAGMENT_SEPERATOR)),d=c(a);if("on"!=b&&(!d||"string"!=typeof d))throw new Error("Fragment "+b+" not found");return d},e.prototype.collectFragments=function(a,c){var d=this,f=e.FRAGMENT_PATTERN,g=[];return(a.match(f)||[]).forEach(function(a){var b=a.replace(f,function(a,b){return b}),a=d.fragmentPath(c,b);if(a){var e=new RegExp(f.source.replace(/\((.*)\)/,b));if(a.match(e))throw new Error("Recursive fragment usage detected on "+b+".");g.push(a);var h=g.filter(function(a){return a.match(new RegExp("fragment "+b))});h.length>0&&f.test(a)&&d.collectFragments(a,c).forEach(function(a){g.unshift(a)})}}),b(g)},e.prototype.processQuery=function(a,b){var c=e.FRAGMENT_PATTERN,d=this.collectFragments(a,b);return a=a.replace(c,function(a,b){return"... "+b.split(".").join(FRAGMENT_SEPERATOR)}),[a].concat(d.filter(function(b){return!a.match(b)})).join("\n")},e.prototype.autoDeclare=function(a,b){var c={string:"String",number:"Int","boolean":"Boolean"};return a.replace(e.AUTODECLARE_PATTERN,function(){var a=[];for(var d in b){var e=b[d],f=d.split("!"),g=f[1]||c[typeof e];g&&a.push("$"+f[0]+": "+g+"!")}return a=a.join(", "),a?"("+a+")":""})},e.prototype.cleanAutoDeclareAnnotations=function(a){a||(a={});var b={};for(var c in a){var d=a[c],e=c.split("!");b[e[0]]=d}return b},e.prototype.buildFragments=function(a){var b=this;a=this.flatten(a||{});var c={};for(var d in a){var e=a[d];"object"==typeof e?c[d]=b.buildFragments(e):c[d]="\nfragment "+d+" "+e}return c},e.prototype.buildQuery=function(a,b){return this.autoDeclare(this.processQuery(a,this._fragments,b),b)},e.prototype.createSenderFunction=function(b){var e=this;return function(f){if(d(f))return e.run(e.ql.apply(e,arguments));var g=function(d,g){g||(g={}),d||(d={});var h=e.buildQuery(f,d);return headers=a(e.options.headers||{},g.headers||{}),new Promise(function(a,f){c(e.options.method||"post",b,headers,{query:h,variables:e.cleanAutoDeclareAnnotations(d)},!!e.options.asJSON,function(b,c){200==c?b.errors?f(b.errors):b.data&&a(b.data):f(b)})})};return arguments.length>1?g.apply(null,Array.prototype.slice.call(arguments,1)):g}},e.prototype.createHelpers=function(a){function b(b){if(d(b)){c.__prefix=this.prefix,c.__suffix=this.suffix;var e=c.run(c.ql.apply(c,arguments));return c.__prefix="",c.__suffix="",e}var f=a(this.prefix+" "+b+" "+this.suffix);return arguments.length>1&&null!=arguments[1]?f.apply(null,Array.prototype.slice.call(arguments,1)):f}var c=this,e=[{method:"mutate",type:"mutation"},{method:"query",type:"query"},{method:"subscribe",type:"subscription"}];e.forEach(function(a){c[a.method]=function(d,e,f){return c.options.alwaysAutodeclare===!0||f&&f.declare===!0?b.call({prefix:a.type+" (@autodeclare) {",suffix:"}"},d,e):b.call({prefix:a.type,suffix:""},d,e)},c[a.method].run=function(b,d){return c[a.method](b,d)({})}}),this.run=function(b){return a(b,{})}},e.prototype.fragments=function(){return this._fragments},e.prototype.getOptions=function(){return this.options||{}},e.prototype.headers=function(b){return this.options.headers=a(this.options.headers,b)},e.prototype.fragment=function(b){if("string"==typeof b){var c=this._fragments[b.replace(/\./g,FRAGMENT_SEPERATOR)];if(!c)throw"Fragment "+b+" not found!";return c.trim()}return this.options.fragments=a(!0,this.options.fragments,b),this._fragments=this.buildFragments(this.options.fragments),this._fragments},e.prototype.ql=function(a){fragments=Array.prototype.slice.call(arguments,1),fragments=fragments.map(function(a){return"string"==typeof a?a.match(/fragment\s+([^\s]*)\s/)[1]:void 0});var b="string"==typeof a?a:a.reduce(function(a,b,c){return a+fragments[c-1]+b});return b=this.buildQuery(b),b=((this.__prefix||"")+" "+b+" "+(this.__suffix||"")).trim()},function(a,b){"function"==typeof define&&define.amd?define(function(){return a.graphql=b(e)}):"object"==typeof module&&module.exports?module.exports=b(a.GraphQLClient):a.graphql=b(a.GraphQLClient)}(this,function(){return e})}();
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: graphqljs-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fatih Kadir Akın
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-05-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: railties
|