graphqljs-rails 0.3.4 → 0.3.5

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: c709ef16ee29aaa76aca8b3904e96c99a9069f34
4
- data.tar.gz: e9c37274f880d4f495675f7c650916678d4bdb4a
3
+ metadata.gz: d6fd1ba21cc570be9e71909a71f3bbf455880a62
4
+ data.tar.gz: f046e990d86bdb96e556a924e7abefc150472d81
5
5
  SHA512:
6
- metadata.gz: 435fa15a6fb36ec07ec35469d757a2c4a7a38ba5591fd2c73df62e6c1cf578965643f19e736a2e819c9656aed5d01c14b57ff353c31f7a422d000a97af82d02f
7
- data.tar.gz: 6d556327b4f308fd2142e6f7532e621266999ab1e1855189ee758b7454581c52cca5e58bb2c2a0a3adfb7db3189b772f7826642a1f874ccf52fd2da3a667e198
6
+ metadata.gz: edc6a446d3eb0f0ac763766da7edf058a08c560a2902d6a798340f7ff3db091c76a04ab2afcde4a6d0a459b71d2b3236f2e1e483c9c3793180e0ca7e4f53fdc2
7
+ data.tar.gz: 2f8aa3f7253092c8347dc9610df8bff9acbdfef504a5fd27a5dcbc05b71a995054e76525da0af9ea36e64b48707669421a4f725749406b1f4314edad46617ad8
data/README.md CHANGED
@@ -1,11 +1,22 @@
1
1
  # GraphQL.js for Rails
2
2
 
3
+ Adds [GraphQL.js](https://github.com/f/graphql.js) to your asset pipeline.
4
+
5
+ ## Features
6
+
7
+ - Nothing depended, plain vanilla JavaScript.
8
+ - Plug & Play.
9
+ - Runs on most of the browsers.
10
+ - **For more information and read how to use GraphQL.js in your Rails application, visit [f/graphql.js] (https://github.com/f/graphql.js)**
11
+
12
+ If you are **looking for a server** try [GraphQL-Ruby](https://github.com/rmosolgo/graphql-ruby). This gem works with [GraphQL-Ruby](https://github.com/rmosolgo/graphql-ruby).
13
+
3
14
  ## Installation
4
15
 
5
16
  Add this line to your application's Gemfile:
6
17
 
7
18
  ```ruby
8
- gem 'graphqljs-rails', '<version>'
19
+ gem 'graphqljs-rails'
9
20
  ```
10
21
 
11
22
  And then execute:
@@ -14,7 +25,14 @@ And then execute:
14
25
 
15
26
  And install it to your `application.js`:
16
27
 
17
- //= require graphql
28
+ ```js
29
+ //= require graphql
30
+ var graph = graphql("/graphql", {
31
+ fragments: {
32
+ ...
33
+ }
34
+ })
35
+ ```
18
36
 
19
37
  ## License
20
38
 
@@ -115,16 +115,21 @@
115
115
  ;(query.match(fragmentRegexp)||[]).forEach(function (fragment) {
116
116
  var path = fragment.replace(fragmentRegexp, function (_, $m) {return $m})
117
117
  var fragment = that.fragmentPath(fragments, path)
118
- var pathRegexp = new RegExp(fragmentRegexp.source.replace(/\((.*)\)/, path))
119
- if (fragment.match(pathRegexp)) {
120
- throw "Recursive fragment usage detected on " + path + "."
121
- }
122
- collectedFragments.push(fragment)
123
- // Collect sub fragments
124
- if (collectedFragments.filter(function (alreadyCollected) { return alreadyCollected.match(new RegExp("fragment " + path)) }).length > 0 && fragmentRegexp.test(fragment)) {
125
- that.collectFragments(fragment, fragments).forEach(function (fragment) {
126
- collectedFragments.unshift(fragment)
118
+ if (fragment) {
119
+ var pathRegexp = new RegExp(fragmentRegexp.source.replace(/\((.*)\)/, path))
120
+ if (fragment.match(pathRegexp)) {
121
+ throw "Recursive fragment usage detected on " + path + "."
122
+ }
123
+ collectedFragments.push(fragment)
124
+ // Collect sub fragments
125
+ var alreadyCollectedFragments = collectedFragments.filter(function (alreadyCollected) {
126
+ return alreadyCollected.match(new RegExp("fragment " + path))
127
127
  })
128
+ if (alreadyCollectedFragments.length > 0 && fragmentRegexp.test(fragment)) {
129
+ that.collectFragments(fragment, fragments).forEach(function (fragment) {
130
+ collectedFragments.unshift(fragment)
131
+ })
132
+ }
128
133
  }
129
134
  })
130
135
  return collectedFragments
@@ -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,b,c,d,e){var f=new XMLHttpRequest;f.open(a,b,!0),f.setRequestHeader("Content-type","application/x-www-form-urlencoded"),f.setRequestHeader("Accept","application/json");for(var g in c)f.setRequestHeader(g,c[g]);f.onerror=function(){e(f,f.status)},f.onload=function(){e(JSON.parse(f.responseText),f.status)},f.send("query="+escape(d.query)+"&variables="+escape(JSON.stringify(d.variables)))}function c(a){return"[object Array]"==Object.prototype.toString.call(a)&&a.raw}function d(a,b){if(!(this instanceof d)){var c=new d(a,b,!0),e=c._sender;for(var f in c)"function"==typeof c[f]&&(e[f]=c[f].bind(c));return e}if(arguments[2]!==!0)throw"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="_",d.AUTOTYPE_PATTERN=/\(@autotype\)/,d.FRAGMENT_PATTERN=/\.\.\.\s*([A-Za-z0-9\.\_]+)/g,d.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},d.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"Fragment "+b+" not found";return d},d.prototype.collectFragments=function(a,b){var c=this,e=d.FRAGMENT_PATTERN,f=[];return(a.match(e)||[]).forEach(function(a){var d=a.replace(e,function(a,b){return b}),a=c.fragmentPath(b,d),g=new RegExp(e.source.replace(/\((.*)\)/,d));if(a.match(g))throw"Recursive fragment usage detected on "+d+".";f.push(a),f.filter(function(a){return a.match(new RegExp("fragment "+d))}).length>0&&e.test(a)&&c.collectFragments(a,b).forEach(function(a){f.unshift(a)})}),f},d.prototype.processQuery=function(a,b){var c=d.FRAGMENT_PATTERN,e=this.collectFragments(a,b);return a=a.replace(c,function(a,b){return"... "+b.split(".").join(FRAGMENT_SEPERATOR)}),[a].concat(e.filter(function(b){return!a.match(b)})).join("\n")},d.prototype.autoType=function(a,b){var c={string:"String",number:"Int","boolean":"Boolean"};return a.replace(d.AUTOTYPE_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+")"})},d.prototype.cleanAutoTypeAnnotations=function(a){a||(a={});var b={};for(var c in a){var d=a[c],e=c.split("!");b[e[0]]=d}return b},d.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},d.prototype.buildQuery=function(a,b){return this.autoType(this.processQuery(a,this._fragments,b),b)},d.prototype.createSenderFunction=function(d){var e=this;return function(f){if(c(f))return e.run(e.ql.apply(e,arguments));var g=function(c,g){g||(g={}),c||(c={});var h=e.buildQuery(f,c);return headers=a(e.options.headers||{},g.headers||{}),new Promise(function(a,f){b(e.options.method||"post",d,headers,{query:h,variables:e.cleanAutoTypeAnnotations(c)},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}},d.prototype.createHelpers=function(a){function b(b){if(c(b)){d.__prefix=this.prefix;var e=d.run(d.ql.apply(d,arguments));return d.__prefix="",e}var f=a(this.prefix+" "+b);return arguments.length>1?f.apply(null,Array.prototype.slice.call(arguments,1)):f}var d=this;this.mutate=b.bind({prefix:"mutation"}),this.query=b.bind({prefix:"query"}),this.subscribe=b.bind({prefix:"subscription"});var e=["mutate","query","subscribe"];e.forEach(function(a){d[a].run=function(b){return d[a](b,{})}}),this.run=function(b){return a(b,{})}},d.prototype.fragments=function(){return this._fragments},d.prototype.getOptions=function(){return this.options},d.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},d.prototype.ql=function(a){fragments=Array.prototype.slice.call(arguments,1),fragments=fragments.map(function(a){return a.match(/fragment\s+([^\s]*)\s/)[1]});var b=this.buildQuery(a.reduce(function(a,b,c){return a+fragments[c-1]+b}));return b=((this.__prefix||"")+" "+b).trim()},function(a,b){"function"==typeof define&&define.amd?define(function(){return a.graphql=b(d)}):"object"==typeof module&&module.exports?module.exports=b(a.GraphQLClient):a.graphql=b(a.GraphQLClient)}(this,function(){return d})}();
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,b,c,d,e){var f=new XMLHttpRequest;f.open(a,b,!0),f.setRequestHeader("Content-type","application/x-www-form-urlencoded"),f.setRequestHeader("Accept","application/json");for(var g in c)f.setRequestHeader(g,c[g]);f.onerror=function(){e(f,f.status)},f.onload=function(){e(JSON.parse(f.responseText),f.status)},f.send("query="+escape(d.query)+"&variables="+escape(JSON.stringify(d.variables)))}function c(a){return"[object Array]"==Object.prototype.toString.call(a)&&a.raw}function d(a,b){if(!(this instanceof d)){var c=new d(a,b,!0),e=c._sender;for(var f in c)"function"==typeof c[f]&&(e[f]=c[f].bind(c));return e}if(arguments[2]!==!0)throw"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="_",d.AUTOTYPE_PATTERN=/\(@autotype\)/,d.FRAGMENT_PATTERN=/\.\.\.\s*([A-Za-z0-9\.\_]+)/g,d.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},d.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"Fragment "+b+" not found";return d},d.prototype.collectFragments=function(a,b){var c=this,e=d.FRAGMENT_PATTERN,f=[];return(a.match(e)||[]).forEach(function(a){var d=a.replace(e,function(a,b){return b}),a=c.fragmentPath(b,d);if(a){var g=new RegExp(e.source.replace(/\((.*)\)/,d));if(a.match(g))throw"Recursive fragment usage detected on "+d+".";f.push(a);var h=f.filter(function(a){return a.match(new RegExp("fragment "+d))});h.length>0&&e.test(a)&&c.collectFragments(a,b).forEach(function(a){f.unshift(a)})}}),f},d.prototype.processQuery=function(a,b){var c=d.FRAGMENT_PATTERN,e=this.collectFragments(a,b);return a=a.replace(c,function(a,b){return"... "+b.split(".").join(FRAGMENT_SEPERATOR)}),[a].concat(e.filter(function(b){return!a.match(b)})).join("\n")},d.prototype.autoType=function(a,b){var c={string:"String",number:"Int","boolean":"Boolean"};return a.replace(d.AUTOTYPE_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+")"})},d.prototype.cleanAutoTypeAnnotations=function(a){a||(a={});var b={};for(var c in a){var d=a[c],e=c.split("!");b[e[0]]=d}return b},d.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},d.prototype.buildQuery=function(a,b){return this.autoType(this.processQuery(a,this._fragments,b),b)},d.prototype.createSenderFunction=function(d){var e=this;return function(f){if(c(f))return e.run(e.ql.apply(e,arguments));var g=function(c,g){g||(g={}),c||(c={});var h=e.buildQuery(f,c);return headers=a(e.options.headers||{},g.headers||{}),new Promise(function(a,f){b(e.options.method||"post",d,headers,{query:h,variables:e.cleanAutoTypeAnnotations(c)},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}},d.prototype.createHelpers=function(a){function b(b){if(c(b)){d.__prefix=this.prefix;var e=d.run(d.ql.apply(d,arguments));return d.__prefix="",e}var f=a(this.prefix+" "+b);return arguments.length>1?f.apply(null,Array.prototype.slice.call(arguments,1)):f}var d=this;this.mutate=b.bind({prefix:"mutation"}),this.query=b.bind({prefix:"query"}),this.subscribe=b.bind({prefix:"subscription"});var e=["mutate","query","subscribe"];e.forEach(function(a){d[a].run=function(b){return d[a](b,{})}}),this.run=function(b){return a(b,{})}},d.prototype.fragments=function(){return this._fragments},d.prototype.getOptions=function(){return this.options},d.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},d.prototype.ql=function(a){fragments=Array.prototype.slice.call(arguments,1),fragments=fragments.map(function(a){return a.match(/fragment\s+([^\s]*)\s/)[1]});var b=this.buildQuery(a.reduce(function(a,b,c){return a+fragments[c-1]+b}));return b=((this.__prefix||"")+" "+b).trim()},function(a,b){"function"==typeof define&&define.amd?define(function(){return a.graphql=b(d)}):"object"==typeof module&&module.exports?module.exports=b(a.GraphQLClient):a.graphql=b(a.GraphQLClient)}(this,function(){return d})}();
@@ -1,5 +1,5 @@
1
1
  module GraphQLJS
2
2
  module Rails
3
- VERSION = "0.3.4"
3
+ VERSION = "0.3.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphqljs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fatih Kadir Akın