pggraphql 0.0.4 → 0.0.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
  SHA1:
3
- metadata.gz: fdf0b9b66504b4787e8ec3e6928426228b531d61
4
- data.tar.gz: c1435f3aaa8d96b2e8d420494d378072a6cded71
3
+ metadata.gz: ce3ae8e16af5b6972f61cacef41f24d9b19f8672
4
+ data.tar.gz: bec017114b149de19a7cdca9a4f5e9d0663e7086
5
5
  SHA512:
6
- metadata.gz: 3d3b0514e72ca3c1dbdc2f92902c1b67537192c0970d82e950b8137b7a115eb2dc03ae13b4159041a890a028849d9df303bd9b7128658ab6b4a61c789ba934e2
7
- data.tar.gz: 7f9dc9e43010a5cf019ba8567077b2751e8de9d22dbe16beb4e21afd0f547cf3df8a881a9b9caff547a9ca651e8078abf42811804331ec9527f43b81fc929a8f
6
+ metadata.gz: 0aa31bbf4d066e4d2265f410e00436dcf773488c5723cacf339b8c13221e948736398d96647c869e0605e03091de3047537d4b30a8bb394de2a0de8559f56cc0
7
+ data.tar.gz: 448db0dd34a71332eec63993039d423ea752df5b2f05521f35b9065c82644da8f4d852939f84e3450f2febf2ff32584b0b4db127b084096e62c877b2992b2049
@@ -1,3 +1,3 @@
1
1
  module Pggraphql
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/pggraphql.rb CHANGED
@@ -54,11 +54,7 @@ module PgGraphQl
54
54
  wheres = []
55
55
 
56
56
  if ids && ids.to_s != "id"
57
- if ids.is_a?(Array)
58
- wheres << "id in (#{ids.join(',')})" unless ids.empty?
59
- else
60
- wheres << "id = #{ids}"
61
- end
57
+ wheres << type.pk.call(ids) if type.pk.call(ids)
62
58
  end
63
59
 
64
60
  wheres << ("(" + type.filter + ")") if type.filter
@@ -102,7 +98,7 @@ module PgGraphQl
102
98
  end
103
99
 
104
100
  class Type
105
- attr_accessor :name, :table, :filter, :links, :order_by, :fields, :subtypes
101
+ attr_accessor :name, :table, :filter, :links, :order_by, :fields, :subtypes, :pk
106
102
  attr_reader :schema, :mappings
107
103
  def initialize(schema, name)
108
104
  @schema = schema
@@ -114,6 +110,17 @@ module PgGraphQl
114
110
  @links = {}
115
111
  @subtypes = {}
116
112
  @mappings = {}
113
+ @pk = ->(ids) do
114
+ if ids.is_a?(Array)
115
+ if ids.empty?
116
+ nil
117
+ else
118
+ "id in (#{ids.join(',')})"
119
+ end
120
+ else
121
+ "id = #{ids}"
122
+ end
123
+ end
117
124
  end
118
125
  def map(field, column_expr)
119
126
  @mappings[field] = column_expr
@@ -53,6 +53,22 @@ module PgGraphQl
53
53
  ), token(res)
54
54
  end
55
55
 
56
+ def test_simple_pk_custom
57
+ res = to_sql({user: {id: "1", email: "email"}}) do |s|
58
+ s.root :user
59
+ s.type :user, fields: [:id, :email], pk: ->(id){ "access_token = '#{id}'" }
60
+ end
61
+
62
+ assert_equal token(<<-SQL
63
+ select 'user'::text as key,
64
+ (select to_json(x.*)
65
+ from (select id,
66
+ email
67
+ from users where access_token = '1' limit 1) x) as value
68
+ SQL
69
+ ), token(res)
70
+ end
71
+
56
72
  def test_simple_pk_array_one
57
73
  res = to_sql({user: {id: [1], email: "email"}}) do |s|
58
74
  s.root :user
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pggraphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek