graphql-functions 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d70a9a955e8b947021e63139526424d70d3a44aa
4
- data.tar.gz: 037b83d3f47e3f3438f598064471dd5d0d452f44
3
+ metadata.gz: 02f0de4e3f1c59ce9d374aaf55ffcb2338ae199e
4
+ data.tar.gz: fef47b3fed57917796499afd266b6f96a38d6bba
5
5
  SHA512:
6
- metadata.gz: 0acd5f944532299b05d22786bf1df63b832110d136785e31131b6e51f1003f9b3704fbc242e5a764b2592b21259e3f48ab0be8772b61e509b78716aed926d879
7
- data.tar.gz: c59f284286fd46a40e06d0f28b8fd624ef87e23b616d89e614da3d4049933c36278b4964f5310da0140387d68e2626d89eab05bd8adca003131d3239b2f83cb9
6
+ metadata.gz: aed01910118028ce08aaaddaa6286f3a1232457645da91dde93ccca3298caf5b55939bdc0d5bca2884c5da420c7231582d86b53f15100abd6777e22b244c6416
7
+ data.tar.gz: 31db237994aabaeff7923741224e1ebba1d25f8676d080565fac8f6d778d7610abff86a0f05c1ea03433a8e77dd87022c873af8fb3aa82ab0a73d478caf5371a
data/README.md CHANGED
@@ -88,10 +88,10 @@ module Functions
88
88
  model ::Person
89
89
  argument :country_code, types.String
90
90
 
91
- def call(obj, args, ctx)
92
- query(obj, args, ctx) do |relation|
93
- relation.where(country_code: args[:countryCode]) if args[:countryCode]
94
- end
91
+ # optional custom logic code.
92
+ # 'relation' represent the data filtered by the built-in array arguments (limit, offset, etc)
93
+ def query(relation, obj, args, ctx)
94
+ relation.where(country_code: args[:countryCode]) if args[:countryCode]
95
95
  end
96
96
  end
97
97
  end
@@ -7,17 +7,16 @@ module GraphQL
7
7
  argument :limit, types.Int
8
8
  argument :offset, types.Int
9
9
 
10
- def call(_, args, _)
11
- query = args[:ids] ? @model_class.where(id: args[:ids]) : @model_class.all
12
- query = query.offset(args[:offset]) if args[:offset]
13
- query = query.limit(args[:limit]) if args[:limit]
14
- query
15
- end
10
+ def call(*attrs)
11
+ _, args, = attrs
12
+ ids_filter = { id: args[:ids] } if args[:ids]
13
+ relation = @model_class
14
+ .all
15
+ .where(ids_filter)
16
+ .offset(args[:offset])
17
+ .limit(args[:limit])
16
18
 
17
- def query(*args)
18
- relation = call(*args)
19
- filtered_relation = yield(relation) if block_given?
20
- filtered_relation || relation
19
+ (query(relation, *attrs) if respond_to?(:query)) || relation
21
20
  end
22
21
 
23
22
  def type
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Functions
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-functions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joaquín Moreira
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-06-14 00:00:00.000000000 Z
12
+ date: 2017-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler