graphqljs-rails 0.4.12 → 0.4.14
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0322440f3d87c180bea4fb72623f62d4487fa6f1
|
4
|
+
data.tar.gz: 7ea6d8d29957b3fa2f734358096353a0f03f08c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eda6f429614a4b0588b79b77851a0e9ecc109bf8e7210259ee98cd47eef8e8ebd0638c31bf797e6b6bed205fd54d6d1afac309c3ff0779f73a601ce9e239e19
|
7
|
+
data.tar.gz: f879e65b3522dbb3508c9e12988b3a60c1fed3ad136e68ca412a0ac6e8aa9123bd6a71a146c62e1a1aeee26d6ddd14dfee8f40a466914e05589f6edd95789e6e
|
@@ -190,7 +190,9 @@
|
|
190
190
|
GraphQLClient.prototype.autoDeclare = function (query, variables) {
|
191
191
|
var typeMap = {
|
192
192
|
string: "String",
|
193
|
-
number:
|
193
|
+
number: function (value) {
|
194
|
+
return value % 1 === 0 ? "Int" : "Float";
|
195
|
+
},
|
194
196
|
boolean: "Boolean"
|
195
197
|
}
|
196
198
|
return query.replace(GraphQLClient.AUTODECLARE_PATTERN, function () {
|
@@ -198,7 +200,9 @@
|
|
198
200
|
for (var key in variables) {
|
199
201
|
var value = variables[key]
|
200
202
|
var keyAndType = key.split("!")
|
201
|
-
var
|
203
|
+
var mapping = typeMap[typeof(value)]
|
204
|
+
var mappedType = typeof(mapping) === "function" ? mapping(value) : mapping
|
205
|
+
var type = (keyAndType[1] || mappedType)
|
202
206
|
if (type) {
|
203
207
|
types.push("$" + keyAndType[0] + ": " + type + "!")
|
204
208
|
}
|
@@ -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(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("https"),m=require("url"),n=m.parse(c),o=("https:"===n.protocol?l:k).request({protocol:n.protocol,hostname:n.hostname,port:n.port,path:n.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)})});o.write(h),o.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,
|
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("https"),m=require("url"),n=m.parse(c),o=("https:"===n.protocol?l:k).request({protocol:n.protocol,hostname:n.hostname,port:n.port,path:n.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)})});o.write(h),o.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){if("object"==typeof a&&a.hasOwnProperty("kind")&&a.hasOwnProperty("definitions"))try{var c=require("graphql");a=c.print(a)}catch(d){throw new Error("You tried to pass a graphql syntax tree but it cannot be compiled to string.")}var f=e.FRAGMENT_PATTERN,g=this.collectFragments(a,b);return a=a.replace(f,function(a,b){return"... "+b.split(".").join(FRAGMENT_SEPERATOR)}),[a].concat(g.filter(function(b){return!a.match(b)})).join("\n")},e.prototype.autoDeclare=function(a,b){var c={string:"String",number:function(a){return a%1===0?"Int":"Float"},"boolean":"Boolean"};return a.replace(e.AUTODECLARE_PATTERN,function(){var a=[];for(var d in b){var e=b[d],f=d.split("!"),g=c[typeof e],h="function"==typeof g?g(e):g,i=f[1]||h;i&&a.push("$"+f[0]+": "+i+"!")}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)},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})}();
|