gql 0.0.3 → 0.0.4
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/README.md +3 -3
- data/lib/gql.rb +2 -0
- data/lib/gql/call.rb +2 -1
- data/lib/gql/connection.rb +3 -20
- data/lib/gql/errors.rb +1 -1
- data/lib/gql/field.rb +1 -1
- data/lib/gql/fields/array.rb +39 -0
- data/lib/gql/fields/connection.rb +4 -3
- data/lib/gql/fields/object.rb +3 -3
- data/lib/gql/node.rb +15 -12
- data/lib/gql/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe2deb60572972e21f7f7371dd4437cd87532043
|
4
|
+
data.tar.gz: 502022ff7d90578776e50bcb84b9d19deddbbd8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b865d13e6b65926e4dad2e418d8cc49882a168e809eeaa372987123714aa6ad761e84f73abef746835fc9964e3683ef6de8f1ea4a91ed8c6b3ce0a0484eeac73
|
7
|
+
data.tar.gz: d1e7b56cd2d314de5a175c19a7f4bde686d0a907c144a6650d2a271876bde255a1e8b1b9ee6b5d8a8ebd7962d9eb81321fed1b9f4b38edbc16800ed87b5f7e10
|
data/README.md
CHANGED
@@ -86,7 +86,7 @@ This should result in the following JSON (after prettyfication):
|
|
86
86
|
"year": 2010,
|
87
87
|
"month": 3
|
88
88
|
},
|
89
|
-
"created": "March
|
89
|
+
"created": "March 05, 2010 20:14",
|
90
90
|
"account": {
|
91
91
|
"bank_name": "Foo Bank",
|
92
92
|
"iban": "987654321",
|
@@ -100,7 +100,7 @@ This should result in the following JSON (after prettyfication):
|
|
100
100
|
"count": 2,
|
101
101
|
"edges": [
|
102
102
|
{
|
103
|
-
"cursor":
|
103
|
+
"cursor": 1,
|
104
104
|
"node": {
|
105
105
|
"artist": "Metallica",
|
106
106
|
"title": "Black Album",
|
@@ -119,7 +119,7 @@ This should result in the following JSON (after prettyfication):
|
|
119
119
|
}
|
120
120
|
}
|
121
121
|
}, {
|
122
|
-
"cursor":
|
122
|
+
"cursor": 2,
|
123
123
|
"node": {
|
124
124
|
"artist": "Nirvana",
|
125
125
|
"title": "Nevermind",
|
data/lib/gql.rb
CHANGED
@@ -20,6 +20,7 @@ module GQL
|
|
20
20
|
end
|
21
21
|
|
22
22
|
module Fields
|
23
|
+
autoload :Array, 'gql/fields/array'
|
23
24
|
autoload :Boolean, 'gql/fields/boolean'
|
24
25
|
autoload :Connection, 'gql/fields/connection'
|
25
26
|
autoload :Float, 'gql/fields/float'
|
@@ -75,6 +76,7 @@ module GQL
|
|
75
76
|
})
|
76
77
|
|
77
78
|
self.field_types.update(
|
79
|
+
array: Fields::Array,
|
78
80
|
boolean: Fields::Boolean,
|
79
81
|
connection: Fields::Connection,
|
80
82
|
float: Fields::Float,
|
data/lib/gql/call.rb
CHANGED
@@ -26,7 +26,8 @@ module GQL
|
|
26
26
|
raise Errors::InvalidNodeClass.new(field_type_class, Fields::Connection)
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
options = { connection_class: connection_class, node_class: node_class }
|
30
|
+
result_class = field_type_class.build_class(nil, options)
|
30
31
|
elsif result_class && !(result_class <= Node)
|
31
32
|
raise Errors::InvalidNodeClass.new(result_class, Node)
|
32
33
|
end
|
data/lib/gql/connection.rb
CHANGED
@@ -8,28 +8,11 @@ module GQL
|
|
8
8
|
def build_class(node_class)
|
9
9
|
node_class ||= self.node_class
|
10
10
|
|
11
|
-
if node_class.nil?
|
12
|
-
raise Errors::UndefinedNodeClass.new(self, 'node')
|
13
|
-
end
|
14
|
-
|
15
|
-
unless node_class <= GQL::Node
|
16
|
-
raise Errors::InvalidNodeClass.new(node_class, GQL::Node)
|
17
|
-
end
|
18
|
-
|
19
11
|
Class.new(self).tap do |connection_class|
|
20
|
-
connection_class.node_class
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def value_of_field(ast_field)
|
26
|
-
if ast_field.name == :edges
|
27
|
-
target.map do |item|
|
28
|
-
node = self.class.node_class.new(ast_field, item, variables, context)
|
29
|
-
node.value
|
12
|
+
connection_class.array :edges, node_class: node_class do
|
13
|
+
target
|
14
|
+
end
|
30
15
|
end
|
31
|
-
else
|
32
|
-
super
|
33
16
|
end
|
34
17
|
end
|
35
18
|
end
|
data/lib/gql/errors.rb
CHANGED
@@ -14,7 +14,7 @@ module GQL
|
|
14
14
|
|
15
15
|
class UndefinedNodeClass < Error
|
16
16
|
def initialize(node_class, name)
|
17
|
-
super("#{node_class} must define a #{name} class. Set it with `self.#{name}_class = My#{
|
17
|
+
super("#{node_class} must define a #{name} class. Set it with `self.#{name}_class = My#{name.camelize}Class`.")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
data/lib/gql/field.rb
CHANGED
@@ -17,7 +17,7 @@ module GQL
|
|
17
17
|
class_attribute :method, instance_accessor: false, instance_predicate: false
|
18
18
|
|
19
19
|
class << self
|
20
|
-
def build_class(method,
|
20
|
+
def build_class(method, options = {})
|
21
21
|
Class.new(self).tap do |field_class|
|
22
22
|
field_class.method = method
|
23
23
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'active_support/core_ext/class/attribute'
|
2
|
+
|
3
|
+
module GQL
|
4
|
+
module Fields
|
5
|
+
class Array < Field
|
6
|
+
class_attribute :node_class, instance_accessor: false, instance_predicate: false
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def build_class(method, options = {})
|
10
|
+
node_class = options[:node_class] || self.node_class
|
11
|
+
|
12
|
+
if node_class.nil?
|
13
|
+
raise Errors::UndefinedNodeClass.new(self, 'node')
|
14
|
+
end
|
15
|
+
|
16
|
+
unless node_class <= GQL::Node
|
17
|
+
raise Errors::InvalidNodeClass.new(node_class, GQL::Node)
|
18
|
+
end
|
19
|
+
|
20
|
+
Class.new(self).tap do |field_class|
|
21
|
+
field_class.method = method
|
22
|
+
field_class.node_class = node_class
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def value
|
28
|
+
target.map do |item|
|
29
|
+
node = self.class.node_class.new(ast_node, item, variables, context)
|
30
|
+
node.value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def raw_value
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -4,10 +4,11 @@ module GQL
|
|
4
4
|
module Fields
|
5
5
|
class Connection < Field
|
6
6
|
class_attribute :connection_class, instance_accessor: false, instance_predicate: false
|
7
|
+
self.connection_class = GQL::Connection
|
7
8
|
|
8
9
|
class << self
|
9
|
-
def build_class(method,
|
10
|
-
connection_class
|
10
|
+
def build_class(method, options = {})
|
11
|
+
connection_class = options[:connection_class] || self.connection_class
|
11
12
|
|
12
13
|
if connection_class.nil?
|
13
14
|
raise Errors::UndefinedNodeClass.new(self, 'connection')
|
@@ -19,7 +20,7 @@ module GQL
|
|
19
20
|
|
20
21
|
Class.new(self).tap do |field_class|
|
21
22
|
field_class.method = method
|
22
|
-
field_class.connection_class = connection_class.build_class(node_class)
|
23
|
+
field_class.connection_class = connection_class.build_class(options[:node_class])
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/lib/gql/fields/object.rb
CHANGED
@@ -6,8 +6,8 @@ module GQL
|
|
6
6
|
class_attribute :node_class, instance_accessor: false, instance_predicate: false
|
7
7
|
|
8
8
|
class << self
|
9
|
-
def build_class(method,
|
10
|
-
node_class
|
9
|
+
def build_class(method, options = {})
|
10
|
+
node_class = options[:node_class] || self.node_class
|
11
11
|
|
12
12
|
if node_class.nil?
|
13
13
|
raise Errors::UndefinedNodeClass.new(self, 'node')
|
@@ -24,7 +24,7 @@ module GQL
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def value
|
28
28
|
node = self.class.node_class.new(ast_node, target, variables, context)
|
29
29
|
node.value
|
30
30
|
end
|
data/lib/gql/node.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/core_ext/class/attribute'
|
2
2
|
require 'active_support/core_ext/string/inflections'
|
3
|
+
require 'active_support/core_ext/array/extract_options'
|
3
4
|
|
4
5
|
module GQL
|
5
6
|
class Node
|
@@ -9,12 +10,6 @@ module GQL
|
|
9
10
|
self.field_classes = {}
|
10
11
|
|
11
12
|
class << self
|
12
|
-
def cursor(method_name)
|
13
|
-
define_method :cursor do
|
14
|
-
target.send(method_name).to_s
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
13
|
def call(*names, &block)
|
19
14
|
names_with_result_class = names.extract_options!
|
20
15
|
|
@@ -31,22 +26,32 @@ module GQL
|
|
31
26
|
end
|
32
27
|
end
|
33
28
|
|
34
|
-
def field(*names,
|
29
|
+
def field(*names, &block)
|
30
|
+
options = names.extract_options!
|
31
|
+
|
35
32
|
names.each do |name|
|
36
33
|
method = block || lambda { target.public_send(name) }
|
37
|
-
field_type_class
|
34
|
+
field_type_class = options.delete(:field_type_class) || Field
|
38
35
|
|
39
36
|
unless field_type_class <= Field
|
40
37
|
raise Errors::InvalidNodeClass.new(field_type_class, Field)
|
41
38
|
end
|
42
39
|
|
43
|
-
field_class = field_type_class.build_class(method,
|
40
|
+
field_class = field_type_class.build_class(method, options)
|
44
41
|
|
45
42
|
self.const_set "#{name.to_s.camelize}Field", field_class
|
46
43
|
self.field_classes = field_classes.merge(name => field_class)
|
47
44
|
end
|
48
45
|
end
|
49
46
|
|
47
|
+
def cursor(name = nil, &block)
|
48
|
+
if name
|
49
|
+
field :cursor, &-> { target.public_send(name) }
|
50
|
+
elsif block_given?
|
51
|
+
field :cursor, &block
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
50
55
|
def method_missing(method, *names, &block)
|
51
56
|
if field_type_class = GQL.field_types[method]
|
52
57
|
options = names.extract_options!
|
@@ -101,14 +106,12 @@ module GQL
|
|
101
106
|
when :node
|
102
107
|
field = self.class.new(ast_field, target, variables, context)
|
103
108
|
field.value
|
104
|
-
when :cursor
|
105
|
-
cursor
|
106
109
|
else
|
107
110
|
method = Field::Method.new(target, context)
|
108
111
|
field_class = self.class.field_classes[ast_field.name]
|
109
112
|
|
110
113
|
if field_class.nil?
|
111
|
-
raise Errors::UndefinedField.new(ast_field.name, self.class)
|
114
|
+
raise Errors::UndefinedField.new(ast_field.name, self.class.superclass)
|
112
115
|
end
|
113
116
|
|
114
117
|
next_target = method.execute(field_class.method)
|
data/lib/gql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Andert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/gql/errors.rb
|
117
117
|
- lib/gql/executor.rb
|
118
118
|
- lib/gql/field.rb
|
119
|
+
- lib/gql/fields/array.rb
|
119
120
|
- lib/gql/fields/boolean.rb
|
120
121
|
- lib/gql/fields/connection.rb
|
121
122
|
- lib/gql/fields/float.rb
|