graphql-functions 0.3.2 → 0.4.0

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
  SHA1:
3
- metadata.gz: 2ad5d0f09c58da345de4830a51574f9130a72563
4
- data.tar.gz: 901d3a2e0aab5231dbdc322e7ced149ac5b01563
3
+ metadata.gz: 20280c76f7dbf2582658fc8f9275d80c978c6d83
4
+ data.tar.gz: 28421554b25956c14aa0e545b2b764b705caf82c
5
5
  SHA512:
6
- metadata.gz: b8a14ab61b9bec85110fed882336db607aab0c8c44ed98ce63a318ed71cb9dd73d42ceaa91cc51ee655fcd3beae267d275ba39cdfca865d9011170a84a835342
7
- data.tar.gz: c0d3122d2b48669df5d1e54ac409cbcd78f6443d792d8d5a686af7ac3d711bb821a735f23d2a9817ef1780a2596b25ac3daafc71294ea5cea4bc72ac5f02f2a0
6
+ metadata.gz: ffe22e28a9b6bad6314e6ed35859c288706d48fe798506fa14f426b1a0c827afb19b253db39eb56abdf7ab4717069bd27a4635a2b61cb88ecfb989b536095584
7
+ data.tar.gz: ffc6de0028113649803170fc41fb69d2aa49e83d1faf18e781a09f4af91290ae35bd0ff55d5a64143bcbe48333735b8de0098eb89922fa8835fcbd9d1ce6f33a
data/README.md CHANGED
@@ -113,8 +113,8 @@ module Types
113
113
  QueryType = GraphQL::ObjectType.define do
114
114
  name "Query"
115
115
 
116
- field :person, function: Functions::Person
117
- field :people, function: Functions::People
116
+ field :person, function: Functions::Person.create
117
+ field :people, function: Functions::People.create
118
118
  end
119
119
  end
120
120
  ```
@@ -137,6 +137,8 @@ Above changes will in addition to the base query capabilities from `graphql-func
137
137
  Element function is intended to be used with a query with a single field output like `person` in the example: The only available argument is id:
138
138
  - `id: Int` Filter by the specified id.
139
139
 
140
+ If `id` is not specified or if the subclass implements its own `query` method which does not return a single element, the first element of the model is returned.
141
+
140
142
  ### Array
141
143
  Array function add filters-like arguments to the query:
142
144
  - `offset: Int` Skip the specified argument of records.
@@ -5,8 +5,12 @@ module GraphQL
5
5
  class Element < Base
6
6
  argument :id, !types.ID
7
7
 
8
- def call(_, args, _)
9
- @model_class.find(args[:id])
8
+ def call(*attrs)
9
+ _, args, = attrs
10
+ return @model_class.find(args[:id]) if args[:id]
11
+ return @model_class.first unless respond_to?(:query)
12
+ relation = query(@model_class, *attrs)
13
+ relation.is_a?(ActiveRecord::Relation) ? relation.first : relation
10
14
  end
11
15
 
12
16
  def type
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Functions
3
- VERSION = '0.3.2'.freeze
3
+ VERSION = '0.4.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.3.2
4
+ version: 0.4.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-08-09 00:00:00.000000000 Z
12
+ date: 2017-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler