gql 0.0.5 → 0.0.6
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/lib/gql.rb +21 -26
- data/lib/gql/array.rb +36 -0
- data/lib/gql/boolean.rb +4 -0
- data/lib/gql/call.rb +14 -9
- data/lib/gql/config.rb +8 -0
- data/lib/gql/connection.rb +27 -6
- data/lib/gql/field.rb +0 -4
- data/lib/gql/node.rb +8 -11
- data/lib/gql/number.rb +6 -0
- data/lib/gql/object.rb +32 -0
- data/lib/gql/schema/call.rb +1 -1
- data/lib/gql/schema/field.rb +2 -2
- data/lib/gql/schema/list.rb +10 -0
- data/lib/gql/schema/node.rb +2 -2
- data/lib/gql/simple.rb +7 -0
- data/lib/gql/string.rb +8 -0
- data/lib/gql/version.rb +1 -1
- metadata +8 -9
- data/lib/gql/fields/array.rb +0 -42
- data/lib/gql/fields/boolean.rb +0 -6
- data/lib/gql/fields/connection.rb +0 -39
- data/lib/gql/fields/float.rb +0 -6
- data/lib/gql/fields/integer.rb +0 -8
- data/lib/gql/fields/object.rb +0 -38
- data/lib/gql/fields/string.rb +0 -11
- data/lib/gql/schema/connection.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20b402e587fe168bb43d6b683c6f41d5d313d828
|
4
|
+
data.tar.gz: 5b5a28f87cce7e5e72df1ef7d366ae06689b269a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ce7cd9bf3934dbc32adf6c6d1c69db6f1c8cbe78cdc8a0eb3aefcaa7a9f2511a385ffab599a2fe1bac156df59249fdcecaf73f40b2daf43ffd9e5fb5b5280ce
|
7
|
+
data.tar.gz: 910724d32eb06b282a067955789b2ff554dbe1034911a6e033e18720ab2b140126e85548e2d6c23e1b06fc1f48e77977d6384a712e8d70c0023f505de534f24e
|
data/lib/gql.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
module GQL
|
2
|
+
autoload :Array, 'gql/array'
|
3
|
+
autoload :Boolean, 'gql/boolean'
|
2
4
|
autoload :Call, 'gql/call'
|
3
5
|
autoload :Config, 'gql/config'
|
4
6
|
autoload :Connection, 'gql/connection'
|
7
|
+
autoload :Error, 'gql/errors'
|
5
8
|
autoload :Executor, 'gql/executor'
|
6
9
|
autoload :Field, 'gql/field'
|
10
|
+
autoload :List, 'gql/list'
|
7
11
|
autoload :Node, 'gql/node'
|
12
|
+
autoload :Number, 'gql/number'
|
13
|
+
autoload :Object, 'gql/object'
|
8
14
|
autoload :Parser, 'gql/parser'
|
15
|
+
autoload :Simple, 'gql/simple'
|
16
|
+
autoload :String, 'gql/string'
|
9
17
|
autoload :Tokenizer, 'gql/tokenizer'
|
10
18
|
autoload :VERSION, 'gql/version'
|
11
19
|
|
@@ -19,20 +27,10 @@ module GQL
|
|
19
27
|
autoload :UndefinedFieldType, 'gql/errors'
|
20
28
|
end
|
21
29
|
|
22
|
-
module Fields
|
23
|
-
autoload :Array, 'gql/fields/array'
|
24
|
-
autoload :Boolean, 'gql/fields/boolean'
|
25
|
-
autoload :Connection, 'gql/fields/connection'
|
26
|
-
autoload :Float, 'gql/fields/float'
|
27
|
-
autoload :Integer, 'gql/fields/integer'
|
28
|
-
autoload :Object, 'gql/fields/object'
|
29
|
-
autoload :String, 'gql/fields/string'
|
30
|
-
end
|
31
|
-
|
32
30
|
module Schema
|
33
31
|
autoload :Call, 'gql/schema/call'
|
34
|
-
autoload :Connection, 'gql/schema/connection'
|
35
32
|
autoload :Field, 'gql/schema/field'
|
33
|
+
autoload :List, 'gql/schema/list'
|
36
34
|
autoload :Node, 'gql/schema/node'
|
37
35
|
autoload :Parameter, 'gql/schema/parameter'
|
38
36
|
autoload :Placeholder, 'gql/schema/placeholder'
|
@@ -43,7 +41,7 @@ module GQL
|
|
43
41
|
Thread.current[:gql_config] ||= Config.new
|
44
42
|
end
|
45
43
|
|
46
|
-
%w(root_node_class field_types).each do |method|
|
44
|
+
%w(root_node_class field_types default_list_class).each do |method|
|
47
45
|
module_eval <<-DELEGATORS, __FILE__, __LINE__ + 1
|
48
46
|
def #{method}
|
49
47
|
config.#{method}
|
@@ -78,24 +76,21 @@ module GQL
|
|
78
76
|
tokenizer = Tokenizer.new
|
79
77
|
tokenizer.scan_setup input
|
80
78
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
[].tap do |result|
|
80
|
+
while token = tokenizer.next_token
|
81
|
+
result << token
|
82
|
+
yield token if block_given?
|
83
|
+
end
|
86
84
|
end
|
87
|
-
|
88
|
-
result
|
89
85
|
end
|
90
86
|
})
|
91
87
|
|
92
88
|
self.field_types.update(
|
93
|
-
array:
|
94
|
-
boolean:
|
95
|
-
connection:
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
string: Fields::String
|
89
|
+
array: Array,
|
90
|
+
boolean: Boolean,
|
91
|
+
connection: Connection,
|
92
|
+
number: Number,
|
93
|
+
object: Object,
|
94
|
+
string: String
|
100
95
|
)
|
101
96
|
end
|
data/lib/gql/array.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support/core_ext/class/attribute'
|
2
|
+
|
3
|
+
module GQL
|
4
|
+
class Array < Field
|
5
|
+
class_attribute :item_class, instance_accessor: false, instance_predicate: false
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def build_class(id, method, options = {})
|
9
|
+
item_class = options[:item_class] || self.item_class
|
10
|
+
|
11
|
+
if item_class.nil?
|
12
|
+
raise Errors::UndefinedNodeClass.new(self, 'item')
|
13
|
+
end
|
14
|
+
|
15
|
+
unless item_class <= Node
|
16
|
+
raise Errors::InvalidNodeClass.new(item_class, Node)
|
17
|
+
end
|
18
|
+
|
19
|
+
Class.new(self).tap do |field_class|
|
20
|
+
field_class.id = id.to_s
|
21
|
+
field_class.method = method
|
22
|
+
field_class.item_class = item_class
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
call :size, Number, -> { target.size }
|
28
|
+
|
29
|
+
def value
|
30
|
+
target.map do |item|
|
31
|
+
node = self.class.item_class.new(ast_node, item, variables, context)
|
32
|
+
node.value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/gql/boolean.rb
ADDED
data/lib/gql/call.rb
CHANGED
@@ -16,18 +16,23 @@ module GQL
|
|
16
16
|
|
17
17
|
class << self
|
18
18
|
def build_class(id, result_class, method)
|
19
|
-
if result_class.is_a? Array
|
20
|
-
|
21
|
-
|
19
|
+
if result_class.is_a? ::Array
|
20
|
+
if result_class.size == 1
|
21
|
+
result_class.unshift GQL.default_list_class || Connection
|
22
|
+
end
|
23
|
+
|
24
|
+
list_class, item_class = result_class
|
22
25
|
|
23
|
-
|
26
|
+
unless list_class <= Connection
|
27
|
+
raise Errors::InvalidNodeClass.new(list_class, Connection)
|
28
|
+
end
|
24
29
|
|
25
|
-
unless
|
26
|
-
raise Errors::InvalidNodeClass.new(
|
30
|
+
unless item_class <= Node
|
31
|
+
raise Errors::InvalidNodeClass.new(list_class, Node)
|
27
32
|
end
|
28
33
|
|
29
|
-
options = {
|
30
|
-
result_class =
|
34
|
+
options = { list_class: list_class, item_class: item_class }
|
35
|
+
result_class = Connection.build_class(:result, nil, options)
|
31
36
|
elsif result_class && !(result_class <= Node)
|
32
37
|
raise Errors::InvalidNodeClass.new(result_class, Node)
|
33
38
|
end
|
@@ -60,7 +65,7 @@ module GQL
|
|
60
65
|
|
61
66
|
private
|
62
67
|
def substitute_variables(args)
|
63
|
-
args.map { |arg| arg.is_a?(Symbol) ? variables[arg] : arg }
|
68
|
+
args.map { |arg| arg.is_a?(::Symbol) ? variables[arg] : arg }
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
data/lib/gql/config.rb
CHANGED
data/lib/gql/connection.rb
CHANGED
@@ -1,15 +1,36 @@
|
|
1
1
|
require 'active_support/core_ext/class/attribute'
|
2
2
|
|
3
3
|
module GQL
|
4
|
-
class Connection <
|
5
|
-
class_attribute :
|
4
|
+
class Connection < Field
|
5
|
+
class_attribute :list_class, instance_accessor: false, instance_predicate: false
|
6
|
+
class_attribute :item_class, instance_accessor: false, instance_predicate: false
|
6
7
|
|
7
8
|
class << self
|
8
|
-
def build_class(
|
9
|
-
|
9
|
+
def build_class(id, method, options = {})
|
10
|
+
list_class = options[:list_class] || self.list_class || GQL.default_list_class
|
11
|
+
item_class = options[:item_class] || self.item_class
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
if list_class.nil?
|
14
|
+
raise Errors::UndefinedNodeClass.new(self, 'list')
|
15
|
+
end
|
16
|
+
|
17
|
+
unless list_class <= Connection
|
18
|
+
raise Errors::InvalidNodeClass.new(list_class, Connection)
|
19
|
+
end
|
20
|
+
|
21
|
+
if item_class.nil?
|
22
|
+
raise Errors::UndefinedNodeClass.new(self, 'item')
|
23
|
+
end
|
24
|
+
|
25
|
+
unless item_class <= Node
|
26
|
+
raise Errors::InvalidNodeClass.new(item_class, Node)
|
27
|
+
end
|
28
|
+
|
29
|
+
Class.new(list_class).tap do |field_class|
|
30
|
+
field_class.id = id.to_s
|
31
|
+
field_class.method = method
|
32
|
+
|
33
|
+
field_class.array :edges, item_class: item_class do
|
13
34
|
target
|
14
35
|
end
|
15
36
|
end
|
data/lib/gql/field.rb
CHANGED
data/lib/gql/node.rb
CHANGED
@@ -29,13 +29,13 @@ module GQL
|
|
29
29
|
|
30
30
|
ids.each do |id|
|
31
31
|
method = block || lambda { target.public_send(id) }
|
32
|
-
|
32
|
+
field_type = options.delete(:type) || Field
|
33
33
|
|
34
|
-
unless
|
35
|
-
raise Errors::InvalidNodeClass.new(
|
34
|
+
unless field_type <= Field
|
35
|
+
raise Errors::InvalidNodeClass.new(field_type, Field)
|
36
36
|
end
|
37
37
|
|
38
|
-
field_class =
|
38
|
+
field_class = field_type.build_class(id, method, options)
|
39
39
|
|
40
40
|
self.const_set "#{id.to_s.camelize}Field", field_class
|
41
41
|
self.fields = fields.merge(id.to_sym => field_class)
|
@@ -43,18 +43,15 @@ module GQL
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def cursor(id = nil, &block)
|
46
|
-
|
47
|
-
|
48
|
-
elsif block_given?
|
49
|
-
field :cursor, &block
|
50
|
-
end
|
46
|
+
body = id ? -> { target.public_send(id) } : block
|
47
|
+
field :cursor, { type: Simple }, &body
|
51
48
|
end
|
52
49
|
|
53
50
|
def method_missing(method, *ids, &block)
|
54
|
-
if
|
51
|
+
if field_type = GQL.field_types[method]
|
55
52
|
options = ids.extract_options!
|
56
53
|
|
57
|
-
field(*ids, options.merge(
|
54
|
+
field(*ids, options.merge(type: field_type), &block)
|
58
55
|
else
|
59
56
|
super
|
60
57
|
end
|
data/lib/gql/number.rb
ADDED
data/lib/gql/object.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/core_ext/class/attribute'
|
2
|
+
|
3
|
+
module GQL
|
4
|
+
class Object < Field
|
5
|
+
class_attribute :node_class, instance_accessor: false, instance_predicate: false
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def build_class(id, method, options = {})
|
9
|
+
node_class = options[:node_class] || self.node_class
|
10
|
+
|
11
|
+
if node_class.nil?
|
12
|
+
raise Errors::UndefinedNodeClass.new(self, 'node')
|
13
|
+
end
|
14
|
+
|
15
|
+
unless node_class <= Node
|
16
|
+
raise Errors::InvalidNodeClass.new(node_class, Node)
|
17
|
+
end
|
18
|
+
|
19
|
+
Class.new(self).tap do |field_class|
|
20
|
+
field_class.id = id.to_s
|
21
|
+
field_class.method = method
|
22
|
+
field_class.node_class = node_class
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def value
|
28
|
+
node = self.class.node_class.new(ast_node, target, variables, context)
|
29
|
+
node.value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/gql/schema/call.rb
CHANGED
data/lib/gql/schema/field.rb
CHANGED
@@ -8,11 +8,11 @@ module GQL
|
|
8
8
|
target.name
|
9
9
|
end
|
10
10
|
|
11
|
-
connection :calls, :
|
11
|
+
connection :calls, :list_class => List, :item_class => Call do
|
12
12
|
target.calls.values
|
13
13
|
end
|
14
14
|
|
15
|
-
connection :fields, :
|
15
|
+
connection :fields, :list_class => List, :item_class => Field do
|
16
16
|
target.fields.values
|
17
17
|
end
|
18
18
|
end
|
data/lib/gql/schema/node.rb
CHANGED
@@ -5,11 +5,11 @@ module GQL
|
|
5
5
|
target.name
|
6
6
|
end
|
7
7
|
|
8
|
-
connection :calls, :
|
8
|
+
connection :calls, :list_class => List, :item_class => Call do
|
9
9
|
target.calls.values
|
10
10
|
end
|
11
11
|
|
12
|
-
connection :fields, :
|
12
|
+
connection :fields, :list_class => List, :item_class => Field do
|
13
13
|
target.fields.values
|
14
14
|
end
|
15
15
|
end
|
data/lib/gql/simple.rb
ADDED
data/lib/gql/string.rb
ADDED
data/lib/gql/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Andert
|
@@ -110,28 +110,27 @@ files:
|
|
110
110
|
- bin/setup
|
111
111
|
- gql.gemspec
|
112
112
|
- lib/gql.rb
|
113
|
+
- lib/gql/array.rb
|
114
|
+
- lib/gql/boolean.rb
|
113
115
|
- lib/gql/call.rb
|
114
116
|
- lib/gql/config.rb
|
115
117
|
- lib/gql/connection.rb
|
116
118
|
- lib/gql/errors.rb
|
117
119
|
- lib/gql/executor.rb
|
118
120
|
- lib/gql/field.rb
|
119
|
-
- lib/gql/fields/array.rb
|
120
|
-
- lib/gql/fields/boolean.rb
|
121
|
-
- lib/gql/fields/connection.rb
|
122
|
-
- lib/gql/fields/float.rb
|
123
|
-
- lib/gql/fields/integer.rb
|
124
|
-
- lib/gql/fields/object.rb
|
125
|
-
- lib/gql/fields/string.rb
|
126
121
|
- lib/gql/node.rb
|
122
|
+
- lib/gql/number.rb
|
123
|
+
- lib/gql/object.rb
|
127
124
|
- lib/gql/parser.rb
|
128
125
|
- lib/gql/parser.y
|
129
126
|
- lib/gql/schema/call.rb
|
130
|
-
- lib/gql/schema/connection.rb
|
131
127
|
- lib/gql/schema/field.rb
|
128
|
+
- lib/gql/schema/list.rb
|
132
129
|
- lib/gql/schema/node.rb
|
133
130
|
- lib/gql/schema/parameter.rb
|
134
131
|
- lib/gql/schema/placeholder.rb
|
132
|
+
- lib/gql/simple.rb
|
133
|
+
- lib/gql/string.rb
|
135
134
|
- lib/gql/tokenizer.rb
|
136
135
|
- lib/gql/tokenizer.rex
|
137
136
|
- lib/gql/version.rb
|
data/lib/gql/fields/array.rb
DELETED
@@ -1,42 +0,0 @@
|
|
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(id, 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.id = id.to_s
|
22
|
-
field_class.method = method
|
23
|
-
field_class.node_class = node_class
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
call :size, Integer, -> { target.size }
|
29
|
-
|
30
|
-
def value
|
31
|
-
target.map do |item|
|
32
|
-
node = self.class.node_class.new(ast_node, item, variables, context)
|
33
|
-
node.value
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def raw_value
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/lib/gql/fields/boolean.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute'
|
2
|
-
|
3
|
-
module GQL
|
4
|
-
module Fields
|
5
|
-
class Connection < Field
|
6
|
-
class_attribute :connection_class, instance_accessor: false, instance_predicate: false
|
7
|
-
self.connection_class = GQL::Connection
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def build_class(id, method, options = {})
|
11
|
-
connection_class = options[:connection_class] || self.connection_class
|
12
|
-
|
13
|
-
if connection_class.nil?
|
14
|
-
raise Errors::UndefinedNodeClass.new(self, 'connection')
|
15
|
-
end
|
16
|
-
|
17
|
-
unless connection_class <= GQL::Connection
|
18
|
-
raise Errors::InvalidNodeClass.new(connection_class, GQL::Connection)
|
19
|
-
end
|
20
|
-
|
21
|
-
Class.new(self).tap do |field_class|
|
22
|
-
field_class.id = id.to_s
|
23
|
-
field_class.method = method
|
24
|
-
field_class.connection_class = connection_class.build_class(options[:node_class])
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def value_of_fields(*)
|
30
|
-
connection = self.class.connection_class.new(ast_node, target, variables, context)
|
31
|
-
connection.value
|
32
|
-
end
|
33
|
-
|
34
|
-
def raw_value
|
35
|
-
nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/gql/fields/float.rb
DELETED
data/lib/gql/fields/integer.rb
DELETED
data/lib/gql/fields/object.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute'
|
2
|
-
|
3
|
-
module GQL
|
4
|
-
module Fields
|
5
|
-
class Object < Field
|
6
|
-
class_attribute :node_class, instance_accessor: false, instance_predicate: false
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def build_class(id, 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.id = id.to_s
|
22
|
-
field_class.method = method
|
23
|
-
field_class.node_class = node_class
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def value
|
29
|
-
node = self.class.node_class.new(ast_node, target, variables, context)
|
30
|
-
node.value
|
31
|
-
end
|
32
|
-
|
33
|
-
def raw_value
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/gql/fields/string.rb
DELETED