graphiti_gql 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti_gql/spec_helper.rb +43 -14
- data/lib/graphiti_gql/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9a1b76315488d9389a214fc640f6029d9e1a05a08182ebbdb9ed7958565e4aa
|
4
|
+
data.tar.gz: e4d6952a6929bf8310a99ba5b2d40e3821fe8bad51e89b3012c041fed9f1c47a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30cb9c3f67aa059d0e68845fc64aee6313d9f0d14d36e19024357c619ca15e176d4178ae2836055c22b407a53187038b21b8447007e37fbed04ab70330c12ff4
|
7
|
+
data.tar.gz: 6ece60976b6d36294e9ef01e8521efdf26d9637b28c6fcfec833e3f2a81d493eece073137071e3373f2ac948c786c18e79734904b62e369a1cc0c0353860d71d
|
@@ -2,6 +2,21 @@ module GraphitiGql
|
|
2
2
|
module SpecHelper
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
+
module ScopeTrackable
|
6
|
+
def self.prepended(klass)
|
7
|
+
klass.class_eval do
|
8
|
+
class << self
|
9
|
+
attr_accessor :resolved_scope
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def resolve(scope)
|
15
|
+
self.class.resolved_scope = scope
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
5
20
|
included do
|
6
21
|
extend Forwardable
|
7
22
|
def_delegators :result,
|
@@ -11,31 +26,38 @@ module GraphitiGql
|
|
11
26
|
:nodes,
|
12
27
|
:stats
|
13
28
|
|
29
|
+
Graphiti::Resource.send(:prepend, ScopeTrackable)
|
30
|
+
|
14
31
|
if defined?(RSpec)
|
15
|
-
let(:params)
|
16
|
-
fields = []
|
17
|
-
resource.attributes.each_pair do |name, config|
|
18
|
-
(fields << name) if config[:readable]
|
19
|
-
end
|
20
|
-
{ fields: fields }
|
21
|
-
end
|
32
|
+
let(:params) { {} }
|
22
33
|
let(:resource) { described_class }
|
23
34
|
let(:ctx) { {} }
|
35
|
+
let(:only_fields) { [] }
|
36
|
+
let(:except_fields) { [] }
|
24
37
|
|
25
38
|
def self.only_fields(*fields)
|
26
|
-
|
27
|
-
fields.each { |f| params[:fields].select! { |p| p == f } }
|
28
|
-
end
|
39
|
+
let(:only_fields) { fields }
|
29
40
|
end
|
30
41
|
|
31
42
|
def self.except_fields(*fields)
|
32
|
-
|
33
|
-
fields.each { |f| params[:fields].reject! { |p| p == f } }
|
34
|
-
end
|
43
|
+
let(:except_fields) { fields }
|
35
44
|
end
|
36
45
|
end
|
37
46
|
end
|
38
47
|
|
48
|
+
def fields
|
49
|
+
fields = []
|
50
|
+
resource.attributes.each_pair do |name, config|
|
51
|
+
(fields << name) if config[:readable]
|
52
|
+
end
|
53
|
+
if respond_to?(:only_fields) && only_fields.present?
|
54
|
+
fields.select! { |f| only_fields.include?(f) }
|
55
|
+
elsif respond_to?(:except_fields) && except_fields.present?
|
56
|
+
fields.reject! { |f| except_fields.include?(f) }
|
57
|
+
end
|
58
|
+
fields
|
59
|
+
end
|
60
|
+
|
39
61
|
def gql_datetime(timestamp, precise = false)
|
40
62
|
if precise
|
41
63
|
timestamp.utc.round(10).iso8601(6)
|
@@ -44,9 +66,16 @@ module GraphitiGql
|
|
44
66
|
end
|
45
67
|
end
|
46
68
|
|
69
|
+
def proxy
|
70
|
+
resource.gql(params.merge(fields: fields), ctx)
|
71
|
+
end
|
72
|
+
|
73
|
+
def query
|
74
|
+
proxy.query
|
75
|
+
end
|
76
|
+
|
47
77
|
def run
|
48
78
|
lambda do
|
49
|
-
proxy = resource.gql(params, ctx)
|
50
79
|
proxy.to_h
|
51
80
|
proxy
|
52
81
|
end
|
data/lib/graphiti_gql/version.rb
CHANGED