gql 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gql/config.rb +1 -1
- data/lib/gql/errors.rb +6 -21
- data/lib/gql/lazy.rb +15 -7
- data/lib/gql/mixins/has_calls.rb +18 -2
- data/lib/gql/mixins/has_fields.rb +4 -4
- data/lib/gql/object.rb +1 -1
- data/lib/gql/registry.rb +1 -3
- data/lib/gql/schema/call.rb +1 -1
- data/lib/gql/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ab57728a3f404a0dc03938f49211795ec0919f9
|
4
|
+
data.tar.gz: b56f90154a8ee4253c76f66404861c53b18254b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22ee10af77dc8cd90b0692b1ca4c91ff36a0bb71e3bd11f0412fc2a9622c784475f38985e6c055e8339a6cc22b7b794ef9309373fbf8c8b7940d67aa18d718c8
|
7
|
+
data.tar.gz: f4c135e4a7325589051a06004a166ab3cd198ce41077da5cfce3673dc76150968faa5f2db98057ad744e78575ab1ee2c247cd69b509f3f185a6bc7f9d3e0b8e3
|
data/lib/gql/config.rb
CHANGED
@@ -78,7 +78,7 @@ module GQL
|
|
78
78
|
|
79
79
|
private
|
80
80
|
def switch_debug_on
|
81
|
-
Field.object :__type__, -> { field_class },
|
81
|
+
Field.object :__type__, -> { field_class }, object_class: Schema::Field
|
82
82
|
Field.send :remove_const, :ExecutionContext if Field.const_defined?(:ExecutionContext)
|
83
83
|
Field.const_set :ExecutionContext, Field::ExecutionContextDebug
|
84
84
|
end
|
data/lib/gql/errors.rb
CHANGED
@@ -2,7 +2,7 @@ require 'active_support/core_ext/array/conversions'
|
|
2
2
|
require 'active_support/core_ext/string/inflections'
|
3
3
|
|
4
4
|
module GQL
|
5
|
-
class Error <
|
5
|
+
class Error < RuntimeError
|
6
6
|
attr_reader :code, :handle
|
7
7
|
|
8
8
|
def initialize(msg, code = 100, handle = nil)
|
@@ -70,16 +70,7 @@ module GQL
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
class
|
74
|
-
def initialize(node_class, name)
|
75
|
-
msg = "#{node_class} must have a #{name.humanize(capitalize: false)} set. "
|
76
|
-
msg << "Set it with `self.#{name} = My#{name.camelize}Class'."
|
77
|
-
|
78
|
-
super(msg, 122)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class InvalidFieldClass < Error
|
73
|
+
class InvalidClass < Error
|
83
74
|
def initialize(node_class, super_class)
|
84
75
|
msg = "#{node_class} must be a (subclass of) #{super_class}."
|
85
76
|
|
@@ -87,16 +78,10 @@ module GQL
|
|
87
78
|
end
|
88
79
|
end
|
89
80
|
|
90
|
-
class
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
@cause = cause
|
95
|
-
|
96
|
-
msg = "Undefined method `#{id}' for #{field_class}. "
|
97
|
-
msg << "Did you try to add a field of type `#{id}'? "
|
98
|
-
msg << "If so, you have to register your field type first "
|
99
|
-
msg << "like this: `GQL.field_types[:#{id}] = My#{id.to_s.camelize}'. "
|
81
|
+
class UnknownFieldType < Error
|
82
|
+
def initialize(type, using_class)
|
83
|
+
msg = "The field type `#{type}' used in #{using_class} is not known."
|
84
|
+
msg << "Register your field type with: `GQL.field_types[:#{type}] = My#{type.to_s.camelize}'. "
|
100
85
|
msg << "The following field types are currently registered: "
|
101
86
|
msg << GQL.field_types.keys.sort.map { |key| "`#{key}'" }.to_sentence
|
102
87
|
|
data/lib/gql/lazy.rb
CHANGED
@@ -7,22 +7,30 @@ module GQL
|
|
7
7
|
class << self
|
8
8
|
def build_class(id, proc, options)
|
9
9
|
Class.new(self).tap do |field_class|
|
10
|
-
field_class.owner
|
11
|
-
field_class.type
|
12
|
-
field_class.id
|
13
|
-
field_class.proc
|
10
|
+
field_class.owner = options.delete(:owner)
|
11
|
+
field_class.type = options.delete(:type)
|
12
|
+
field_class.id = id
|
13
|
+
field_class.proc = proc
|
14
14
|
field_class.options = options
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def spur
|
19
|
+
return spur_unknown_field_type if type.is_a? ::Symbol
|
20
|
+
|
20
21
|
owner.add_field id, proc, options.merge(type: Registry.fetch(type))
|
21
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def spur_unknown_field_type
|
26
|
+
field_type = GQL.field_types[type]
|
27
|
+
raise Errors::UnknownFieldType.new(type, owner) unless field_type
|
28
|
+
owner.send type, id, proc, options
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
def value
|
25
|
-
field_class = self.class.
|
33
|
+
field_class = self.class.spur
|
26
34
|
|
27
35
|
field = field_class.new(ast_node, target, variables, context)
|
28
36
|
field.value
|
data/lib/gql/mixins/has_calls.rb
CHANGED
@@ -53,7 +53,8 @@ module GQL
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def call_class_from_spec(spec)
|
56
|
-
return
|
56
|
+
return LazyCall.new(spec) if spec.is_a?(::String)
|
57
|
+
return Class.new(spec) unless spec.is_a?(::Proc)
|
57
58
|
|
58
59
|
Class.new(Call).tap do |call_class|
|
59
60
|
call_class.class_eval do
|
@@ -102,7 +103,7 @@ module GQL
|
|
102
103
|
end
|
103
104
|
|
104
105
|
def result_class_from_mapping_spec(spec)
|
105
|
-
Object.build_class :result, nil,
|
106
|
+
Object.build_class :result, nil, object_class: spec
|
106
107
|
end
|
107
108
|
end
|
108
109
|
|
@@ -115,6 +116,21 @@ module GQL
|
|
115
116
|
def call_class_for_id(id)
|
116
117
|
self.class.calls[id] or raise Errors::CallNotFound.new(id, self.class)
|
117
118
|
end
|
119
|
+
|
120
|
+
class LazyCall
|
121
|
+
attr_reader :call_class_name
|
122
|
+
attr_accessor :id, :result_class
|
123
|
+
|
124
|
+
def initialize(call_class_name)
|
125
|
+
@call_class_name = call_class_name
|
126
|
+
end
|
127
|
+
|
128
|
+
def execute(caller_class, ast_node, target, variables, context)
|
129
|
+
real_call_class = Registry.fetch(call_class_name, Call)
|
130
|
+
call_class = caller_class.add_call(id, real_call_class, returns: result_class)
|
131
|
+
call_class.execute caller_class, ast_node, target, variables, context
|
132
|
+
end
|
133
|
+
end
|
118
134
|
end
|
119
135
|
end
|
120
136
|
end
|
@@ -54,15 +54,15 @@ module GQL
|
|
54
54
|
define_field_method method, type
|
55
55
|
send method, *args, &block
|
56
56
|
else
|
57
|
-
|
57
|
+
options = args.extract_options!.merge(type: method.to_sym)
|
58
|
+
args = args.push(options)
|
59
|
+
add_field(*args, &block)
|
58
60
|
end
|
59
|
-
rescue NoMethodError => exc
|
60
|
-
raise Errors::NoMethodError.new(self, method, exc)
|
61
61
|
end
|
62
62
|
|
63
63
|
private
|
64
64
|
def build_field_class(type, id, proc, options)
|
65
|
-
if type.is_a? ::
|
65
|
+
if type.is_a?(::String) || type.is_a?(::Symbol)
|
66
66
|
Lazy.build_class id, proc, options.merge(owner: self, type: type)
|
67
67
|
else
|
68
68
|
Registry.fetch(type).build_class id, proc, options
|
data/lib/gql/object.rb
CHANGED
@@ -6,7 +6,7 @@ module GQL
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def build_class(id, proc, options = {})
|
9
|
-
object_class = options.delete(:
|
9
|
+
object_class = options.delete(:object_class) || options.delete(:as)
|
10
10
|
object_class = ::Hash.new(object_class) unless object_class.is_a?(::Hash)
|
11
11
|
|
12
12
|
Class.new(self).tap do |klass|
|
data/lib/gql/registry.rb
CHANGED
@@ -17,8 +17,6 @@ module GQL
|
|
17
17
|
|
18
18
|
def fetch(key, baseclass = Field)
|
19
19
|
cache[key] || begin
|
20
|
-
raise Errors::FieldClassNotSet.new(baseclass, 'TODO') if key.nil?
|
21
|
-
|
22
20
|
const, name =
|
23
21
|
if key.instance_of? ::Class
|
24
22
|
[key, key.name]
|
@@ -26,7 +24,7 @@ module GQL
|
|
26
24
|
[key.constantize, key]
|
27
25
|
end
|
28
26
|
|
29
|
-
raise Errors::
|
27
|
+
raise Errors::InvalidClass.new(const, baseclass) unless const <= baseclass
|
30
28
|
|
31
29
|
cache.update name => const, const => const
|
32
30
|
|
data/lib/gql/schema/call.rb
CHANGED
@@ -5,7 +5,7 @@ module GQL
|
|
5
5
|
|
6
6
|
string :id
|
7
7
|
string :name
|
8
|
-
object :result_class, -> { target.result_class || CallerClass },
|
8
|
+
object :result_class, -> { target.result_class || CallerClass }, object_class: Field
|
9
9
|
array :parameters, -> { (target.proc || target.instance_method(:execute)).parameters }, item_class: Parameter
|
10
10
|
|
11
11
|
def scalar_value
|
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.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Andert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: minitest-
|
70
|
+
name: minitest-reporters
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
75
|
+
version: '1.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
82
|
+
version: '1.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activesupport
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|