pggraphql 0.1.3 → 0.1.4

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: 40388c39022da2118d8ffe8774012034c35e29c5
4
- data.tar.gz: efba25021710edfe95ab788e60fde4013df55736
3
+ metadata.gz: a496c7dcb4e4874d467f306c9c09694fd7eb8cc0
4
+ data.tar.gz: 281ff55e808ed19658b7c83eeaeb45195387903c
5
5
  SHA512:
6
- metadata.gz: 44b8bec7c4351cfa93d23c5b161b3131d1c3125e477f90db0185337831e3cca0dfe5dc3fad44c38facdd8f9f2b58912391ebd043ca2f3245a29f713bc22943a7
7
- data.tar.gz: f725f47496545cf7c63889a145c50e53d5d14d7c260b30fb948f4886824d33e9e24e67427c814ae181f568dc95080dac80b3095144ecf9d08eefde33925c1336
6
+ metadata.gz: f51a3e077d8a80fe633a7a96599f023e4e55e8b537756ef3f19de3802caa0b354afdb957b40de31666bd510a9ca4bf18785307c93a3be7c56c2a7d7b61520631
7
+ data.tar.gz: c019677cec5606e7e842a01b1269d96851d9fda23f648fef1d277123e3af257bd46b6e893b1c1f4a2c04505dd725627b66cd79716b54218af4cf5bd02f37838b
@@ -145,7 +145,7 @@ module PgGraphQl
145
145
 
146
146
  column_expr_proc = -> do
147
147
  if field_def[:expr]
148
- handle_sql_part(field_def[:expr].call(column_name), params, level, table_levels)
148
+ handle_sql_part(field_def[:expr].call(column_name, e[1]), params, level, table_levels)
149
149
  else
150
150
  handle_sql_part("#{column_name}", params, level, table_levels)
151
151
  end
@@ -295,7 +295,7 @@ module PgGraphQl
295
295
  @fields = fields.map{|f| create_field(f)}
296
296
  end
297
297
  def fields
298
- @fields + [create_field({name: :id, as: nil, expr: ->(c){ "#{c}" }})] + (@subtypes.empty? ? [] : [create_field(:type)])
298
+ @fields + [create_field({name: :id, as: nil, expr: ->(c, query){ "#{c}" }})] + (@subtypes.empty? ? [] : [create_field(:type)])
299
299
  end
300
300
  def create_field(field)
301
301
  if field.is_a?(Symbol)
@@ -1,3 +1,3 @@
1
1
  module Pggraphql
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -158,6 +158,23 @@ module PgGraphQl
158
158
  ), token(res[:sql])
159
159
  assert_equal [], res[:params]
160
160
 
161
+ # ---
162
+
163
+ res = to_sql({user: {email: nil, other: nil, :"$custom" => {name: "bob"}}}) do |s|
164
+ s.root :user
165
+ s.type :user, null_pk: :array, fields: [:email, {name: :other, expr: ->(c, query){ "'#{query[:"$custom"][:name]}'" }}]
166
+ end
167
+
168
+ assert_equal token(<<-SQL
169
+ select 'user'::text as key,
170
+ (select to_json(coalesce(json_agg(x.*), '[]'::json))
171
+ from (select users1.id,
172
+ users1.email as email,
173
+ 'bob' as other
174
+ from users as users1) x) as value
175
+ SQL
176
+ ), token(res[:sql])
177
+
161
178
  end
162
179
 
163
180
  def test_simple_igore_dollar_fields
@@ -216,10 +233,12 @@ module PgGraphQl
216
233
 
217
234
  # ----
218
235
 
219
- res = to_sql({user: {id: 1, email: nil}}) do |s|
236
+ res = to_sql({user: {id: 1, email: nil, :"$custom" => {order: "email"}}}) do |s|
220
237
  s.root :user
221
238
  s.type :user, fields: [:email] do |t|
222
- t.table_query = ->(query){ "select 1 as id, 'my@domain' as email" }
239
+ t.table_query = ->(query) do
240
+ "select 1 as id, 'my@domain' as email order by #{query[:"$custom"][:order]} desc"
241
+ end
223
242
  end
224
243
  end
225
244
 
@@ -228,7 +247,7 @@ module PgGraphQl
228
247
  (select to_json(x.*)
229
248
  from (select users1.id,
230
249
  users1.email as email
231
- from (select 1 as id, 'my@domain' as email) as users1
250
+ from (select 1 as id, 'my@domain' as email order by email desc) as users1
232
251
  where users1.id = ? limit 1) x) as value
233
252
  SQL
234
253
  ), token(res[:sql])
@@ -591,7 +610,7 @@ module PgGraphQl
591
610
  res = to_sql({flow: {id: 1, data: nil}}) do |s|
592
611
  s.root :flow
593
612
  s.type :flow do |t|
594
- t.fields = [{name: :data, expr: ->(c){ "to_json(#{c})" } }]
613
+ t.fields = [{name: :data, expr: ->(c, query){ "to_json(#{c})" } }]
595
614
  end
596
615
  end
597
616
 
@@ -606,7 +625,7 @@ module PgGraphQl
606
625
  res = to_sql({flow: {id: 1, data: nil}}) do |s|
607
626
  s.root :flow
608
627
  s.type :flow do |t|
609
- t.fields = [{name: :data, as: nil, expr: ->(c){ "to_json(#{c})" } }]
628
+ t.fields = [{name: :data, as: nil, expr: ->(c, query){ "to_json(#{c})" } }]
610
629
  end
611
630
  end
612
631
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pggraphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json