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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84a7ebf615007ac087b7bab32e53b78fc1bbdb7abcd9d65e38beac1ec7e578fc
4
- data.tar.gz: d5c625d0e34f750d8fc3bc8c71f39ccabb70aa1c87340978620e965137e15feb
3
+ metadata.gz: b9a1b76315488d9389a214fc640f6029d9e1a05a08182ebbdb9ed7958565e4aa
4
+ data.tar.gz: e4d6952a6929bf8310a99ba5b2d40e3821fe8bad51e89b3012c041fed9f1c47a
5
5
  SHA512:
6
- metadata.gz: e8ea8defdb4712239187bcbb14a0d5dbeee9e52bf11a7c32dd747da2eae62247ef66fda15dd63b57886920a895f8215fe7a33b8eb3dc156194b3b2e3fd2f75c6
7
- data.tar.gz: 42f885befb9c54a6b915642e40f2d2bb8704571c901c392f2a6fe11196d805113ca7af546ff15db7b336fdceff172ba2c27e9f443381462db26b4b44461eab6b
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) do
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
- before do
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
- before do
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
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti_gql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond